File tree Expand file tree Collapse file tree
lambdas/api-handler/src/services Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11import { MIRepository } from "@internal/datastore/src/mi-repository" ;
22import { GetMIResponse , IncomingMI , PostMIResponse } from "../contracts/mi" ;
33import { mapToGetMIResponse , mapToPostMIResponse } from "../mappers/mi-mapper" ;
4+ import { ApiErrorDetail } from "../contracts/errors" ;
5+ import NotFoundError from "../errors/not-found-error" ;
6+
7+ function isNotFoundError ( error : any ) {
8+ return (
9+ error instanceof Error &&
10+ / ^ M a n a g e m e n t I n f o r m a t i o n w i t h i d \w + n o t f o u n d f o r s u p p l i e r \w + $ / . test ( error . message )
11+ ) ;
12+ }
413
514export const postMI = async (
615 incomingMi : IncomingMI ,
@@ -14,5 +23,15 @@ export const getMI = async (
1423 supplierId : string ,
1524 miRepo : MIRepository ,
1625) : Promise < GetMIResponse > => {
17- return mapToGetMIResponse ( await miRepo . getMI ( miId , supplierId ) ) ;
26+ let mi ;
27+
28+ try {
29+ mi = await miRepo . getMI ( miId , supplierId ) ;
30+ } catch ( error ) {
31+ if ( isNotFoundError ( error ) ) {
32+ throw new NotFoundError ( ApiErrorDetail . NotFoundId ) ;
33+ }
34+ throw error ;
35+ }
36+ return mapToGetMIResponse ( mi ) ;
1837} ;
You can’t perform that action at this time.
0 commit comments