@@ -19,6 +19,16 @@ class ThreadService extends BaseService {
19
19
this . db = this . services . get ( 'database' ) . get ( DB_WRITE , 'service:thread' ) ;
20
20
21
21
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
+ } ) ;
22
32
23
33
const svc_permission = this . services . get ( 'permission' ) ;
24
34
svc_permission . register_implicator ( PermissionImplicator . create ( {
@@ -183,6 +193,8 @@ class ThreadService extends BaseService {
183
193
}
184
194
185
195
install_threads_endpoints_ ( { router } ) {
196
+ const svc_apiError = this . services . get ( 'api-error' ) ;
197
+
186
198
Endpoint ( {
187
199
route : '/create' ,
188
200
methods : [ 'POST' ] ,
@@ -223,7 +235,7 @@ class ThreadService extends BaseService {
223
235
{
224
236
const parent_thread = await this . get_thread ( { uid : parent_uid } ) ;
225
237
if ( ! parent_thread ) {
226
- throw APIError . create ( 'thread_not_found' , null , {
238
+ throw svc_apiError . create ( 'thread_not_found' , {
227
239
uid : parent_uid ,
228
240
} ) ;
229
241
}
@@ -311,7 +323,7 @@ class ThreadService extends BaseService {
311
323
// Get existing thread
312
324
const thread = await this . get_thread ( { uid } ) ;
313
325
if ( ! thread ) {
314
- throw APIError . create ( 'thread_not_found' , null , {
326
+ throw svc_apiError . create ( 'thread_not_found' , {
315
327
uid,
316
328
} ) ;
317
329
}
@@ -372,7 +384,7 @@ class ThreadService extends BaseService {
372
384
// Get existing thread
373
385
const thread = await this . get_thread ( { uid } ) ;
374
386
if ( ! thread ) {
375
- throw APIError . create ( 'thread_not_found' , null , {
387
+ throw svc_apiError . create ( 'thread_not_found' , {
376
388
uid,
377
389
} ) ;
378
390
}
@@ -539,7 +551,8 @@ class ThreadService extends BaseService {
539
551
) ;
540
552
541
553
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' , {
543
556
uid,
544
557
} ) ;
545
558
}
0 commit comments