Skip to content

Commit 655b93b

Browse files
committed
temp save in ElasticSearchService and handle Internal Server Error
1 parent 0f9cdcc commit 655b93b

File tree

1 file changed

+29
-17
lines changed

1 file changed

+29
-17
lines changed

packages/velog-server/src/lib/elasticSearch/ElasticSearchService.ts

Lines changed: 29 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { injectable, singleton } from 'tsyringe'
44
import { BuildQueryService } from './BuildQueryService.js'
55
import { PostIncludeTags } from '@services/PostService/PostServiceInterface.js'
66
import { Post } from '@prisma/client'
7+
import { InternalServerError } from '@errors/InternalServerError.js'
78

89
interface Service {
910
get client(): Client
@@ -138,26 +139,37 @@ export class ElasticSearchService implements Service {
138139

139140
query.script_score.query.bool.must.push(privatePostsQuery)
140141

141-
const result = await this.client.search({
142-
index: 'posts',
143-
body: {
144-
from,
145-
size,
146-
query,
147-
},
148-
})
142+
try {
143+
const result = await this.client.search({
144+
index: 'posts',
145+
body: {
146+
from,
147+
size,
148+
query,
149+
},
150+
})
149151

150-
const posts = result.body.hits.hits.map((hit: any) => hit._source)
151-
posts.forEach((p: any) => {
152-
p.released_at = new Date(p.released_at)
153-
})
152+
console.log('result', result)
154153

155-
const data = {
156-
count: result.body.hits.total.value,
157-
posts: result.body.hits.hits.map((hit: any) => hit._source),
158-
}
154+
const posts = result.body.hits.hits.map((hit: any) => hit._source)
155+
posts.forEach((p: any) => {
156+
p.released_at = new Date(p.released_at)
157+
})
158+
159+
const data = {
160+
count: result.body.hits.total.value,
161+
posts: result.body.hits.hits.map((hit: any) => hit._source),
162+
}
159163

160-
return data
164+
// TODO: bug fix for elastic search
165+
return {
166+
count: 0,
167+
posts: [],
168+
}
169+
} catch (error) {
170+
console.log(error)
171+
throw new InternalServerError('Internal Server Error')
172+
}
161173
}
162174
}
163175

0 commit comments

Comments
 (0)