@@ -214,10 +214,14 @@ export class AuthProviderService {
214
214
await this . authProviderDB . delete ( authProvider ) ;
215
215
}
216
216
217
- async getAuthProvider ( userId : string , id : string ) : Promise < AuthProviderEntry | undefined > {
217
+ /**
218
+ * Returns the provider identified by the specified `id`. Throws `NOT_FOUND` error if the resource
219
+ * is not found.
220
+ */
221
+ async getAuthProvider ( userId : string , id : string ) : Promise < AuthProviderEntry > {
218
222
const result = await this . authProviderDB . findById ( id ) ;
219
223
if ( ! result ) {
220
- return undefined ;
224
+ throw new ApplicationError ( ErrorCodes . NOT_FOUND , "Provider resource not found." ) ;
221
225
}
222
226
223
227
if ( result . organizationId ) {
@@ -266,7 +270,7 @@ export class AuthProviderService {
266
270
const { id, ownerId } = entry ;
267
271
const existing = ( await this . authProviderDB . findByUserId ( ownerId ) ) . find ( ( p ) => p . id === id ) ;
268
272
if ( ! existing ) {
269
- throw new Error ( "Provider does not exist ." ) ;
273
+ throw new ApplicationError ( ErrorCodes . NOT_FOUND , "Provider resource not found ." ) ;
270
274
}
271
275
const changed =
272
276
entry . clientId !== existing . oauth . clientId ||
@@ -325,7 +329,7 @@ export class AuthProviderService {
325
329
// TODO can we change this to query for the provider by id and org instead of loading all from org?
326
330
const existing = ( await this . authProviderDB . findByOrgId ( organizationId ) ) . find ( ( p ) => p . id === id ) ;
327
331
if ( ! existing ) {
328
- throw new Error ( "Provider does not exist ." ) ;
332
+ throw new ApplicationError ( ErrorCodes . NOT_FOUND , "Provider resource not found ." ) ;
329
333
}
330
334
const changed =
331
335
entry . clientId !== existing . oauth . clientId ||
@@ -368,7 +372,7 @@ export class AuthProviderService {
368
372
break ;
369
373
}
370
374
if ( ! urls ) {
371
- throw new Error ( "Unexpected service type." ) ;
375
+ throw new ApplicationError ( ErrorCodes . BAD_REQUEST , "Unexpected service type." ) ;
372
376
}
373
377
const oauth : AuthProviderEntry [ "oauth" ] = {
374
378
...urls ,
0 commit comments