Skip to content

Commit 95ddfe3

Browse files
committed
fix: error handling in ThreadService
1 parent fc11eba commit 95ddfe3

File tree

1 file changed

+17
-4
lines changed

1 file changed

+17
-4
lines changed

src/backend/src/services/ThreadService.js

+17-4
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,16 @@ class ThreadService extends BaseService {
1919
this.db = this.services.get('database').get(DB_WRITE, 'service:thread');
2020

2121
this.thread_body_max_size = 4 * 1024; // 4KiB
22+
23+
const svc_apiError = this.services.get('api-error');
24+
svc_apiError.register({
25+
'thread_not_found': {
26+
status: 400,
27+
message: ({ uid }) => {
28+
return `Thread with UID ${uid} was not found`;
29+
}
30+
},
31+
});
2232

2333
const svc_permission = this.services.get('permission');
2434
svc_permission.register_implicator(PermissionImplicator.create({
@@ -183,6 +193,8 @@ class ThreadService extends BaseService {
183193
}
184194

185195
install_threads_endpoints_ ({ router }) {
196+
const svc_apiError = this.services.get('api-error');
197+
186198
Endpoint({
187199
route: '/create',
188200
methods: ['POST'],
@@ -223,7 +235,7 @@ class ThreadService extends BaseService {
223235
{
224236
const parent_thread = await this.get_thread({ uid: parent_uid });
225237
if ( !parent_thread ) {
226-
throw APIError.create('thread_not_found', null, {
238+
throw svc_apiError.create('thread_not_found', {
227239
uid: parent_uid,
228240
});
229241
}
@@ -311,7 +323,7 @@ class ThreadService extends BaseService {
311323
// Get existing thread
312324
const thread = await this.get_thread({ uid });
313325
if ( !thread ) {
314-
throw APIError.create('thread_not_found', null, {
326+
throw svc_apiError.create('thread_not_found', {
315327
uid,
316328
});
317329
}
@@ -372,7 +384,7 @@ class ThreadService extends BaseService {
372384
// Get existing thread
373385
const thread = await this.get_thread({ uid });
374386
if ( !thread ) {
375-
throw APIError.create('thread_not_found', null, {
387+
throw svc_apiError.create('thread_not_found', {
376388
uid,
377389
});
378390
}
@@ -539,7 +551,8 @@ class ThreadService extends BaseService {
539551
);
540552

541553
if ( !thread ) {
542-
throw APIError.create('thread_not_found', null, {
554+
const svc_apiError = this.services.get('api-error');
555+
throw svc_apiError.create('thread_not_found', {
543556
uid,
544557
});
545558
}

0 commit comments

Comments
 (0)