Skip to content

Commit ed80a99

Browse files
committed
chore: add update&create post error log
1 parent 31fa40f commit ed80a99

File tree

1 file changed

+28
-18
lines changed
  • apps/server/src/services/PostApiService

1 file changed

+28
-18
lines changed

apps/server/src/services/PostApiService/index.mts

Lines changed: 28 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
1+
import geoip from 'geoip-country'
2+
import { customAlphabet } from 'nanoid'
13
import { EditPostInput, WritePostInput } from '@graphql/helpers/generated.js'
24
import { DbService } from '@lib/db/DbService.js'
35
import { UtilsService } from '@lib/utils/UtilsService.js'
46
import { injectable, singleton } from 'tsyringe'
5-
import { customAlphabet } from 'nanoid'
67
import { TagService } from '@services/TagService/index.js'
78
import { PostTagService } from '@services/PostTagService/index.js'
89
import { Time } from '@constants/TimeConstants.js'
910
import { DiscordService } from '@lib/discord/DiscordService.js'
1011
import { UnauthorizedError } from '@errors/UnauthorizedError.js'
1112
import { NotFoundError } from '@errors/NotfoundError.js'
1213
import { BadRequestError } from '@errors/BadRequestErrors.js'
13-
import geoip from 'geoip-country'
1414
import { Post, Series, Tag } from '@packages/database/velog-rds'
1515
import { ForbiddenError } from '@errors/ForbiddenError.js'
1616
import { SeriesService } from '@services/SeriesService/index.mjs'
@@ -112,12 +112,17 @@ export class PostApiService implements Service {
112112
])
113113
}
114114

115-
await this.db.post.update({
116-
where: {
117-
id: post.id,
118-
},
119-
data,
120-
})
115+
try {
116+
await this.db.post.update({
117+
where: {
118+
id: post.id,
119+
},
120+
data,
121+
})
122+
} catch (error) {
123+
console.error('Prisma update error:', error)
124+
throw new Error('Failed to update post')
125+
}
121126

122127
try {
123128
await Promise.all([
@@ -223,15 +228,20 @@ export class PostApiService implements Service {
223228

224229
let post: Post | null = null
225230
if (type === 'write') {
226-
post = await this.db.post.create({
227-
data: {
228-
...(data as Omit<WritePostInput, 'tags' | 'token' | 'series_id'>),
229-
fk_user_id: signedUserId,
230-
},
231-
include: {
232-
user: true,
233-
},
234-
})
231+
try {
232+
post = await this.db.post.create({
233+
data: {
234+
...(data as Omit<WritePostInput, 'tags' | 'token' | 'series_id'>),
235+
fk_user_id: signedUserId,
236+
},
237+
include: {
238+
user: true,
239+
},
240+
})
241+
} catch (error) {
242+
console.log('Prisma create post error:', error)
243+
throw new Error('Failed to create post')
244+
}
235245
}
236246

237247
if (type === 'edit') {
@@ -323,7 +333,7 @@ export class PostApiService implements Service {
323333
// await this.imageService.trackImages(images, data.body)
324334
// }, 0)
325335

326-
return { data, isPublish, post, userId: signedUserId, series_id }
336+
return { data: { ...data }, isPublish, post, userId: signedUserId, series_id }
327337
}
328338
private async generateUrlSlug({ input, urlSlug, userId }: GenerateUrlSlugArgs) {
329339
let processedUrlSlug = this.utils.escapeForUrl(urlSlug)

0 commit comments

Comments
 (0)