File tree Expand file tree Collapse file tree 2 files changed +39
-3
lines changed Expand file tree Collapse file tree 2 files changed +39
-3
lines changed Original file line number Diff line number Diff line change 11{
22 "name" : " @vesselapi/integrations" ,
3- "version" : " 1.0.76 " ,
3+ "version" : " 1.0.77 " ,
44 "description" : " Vessel integrations" ,
55 "main" : " dist/index.js" ,
66 "module" : " dist/index.mjs" ,
Original file line number Diff line number Diff line change 33 formatUrl ,
44 makeRequestFactory ,
55} from '@/sdk/client' ;
6+ import { IntegrationError } from '@/sdk/error' ;
67import * as custom from '@/sdk/validators' ;
7- import { objectify , shake } from 'radash' ;
8+ import { crush , guard , objectify , shake } from 'radash' ;
89import { z } from 'zod' ;
910import { BASE_URL , DEFAULT_PAGE_SIZE } from './constants' ;
1011import {
@@ -55,7 +56,7 @@ const request = makeRequestFactory(async (auth, options) => {
5556 }
5657 : undefined ,
5758 } ;
58- } ) ;
59+ } , errorMapper ) ;
5960
6061export const client = {
6162 auth : {
@@ -489,3 +490,38 @@ export const client = {
489490 } ,
490491 passthrough : request . passthrough ( ) ,
491492} ;
493+
494+ const ErrorCodes = {
495+ '502: Bad gateway' : 'Bad gateway, apollo api did not respond' ,
496+ } ;
497+
498+ const serializeError = ( error : any ) => {
499+ return (
500+ guard ( ( ) =>
501+ JSON . stringify ( {
502+ name : error . name ,
503+ message : error . message ,
504+ code : error . code ,
505+ stack : error . stack ,
506+ cause : error . cause ,
507+ ...crush ( error ) ,
508+ } ) ,
509+ ) ?? `${ error } `
510+ ) ;
511+ } ;
512+
513+ function errorMapper ( error : any ) {
514+ const err = serializeError ( error ) ;
515+ const errorKey =
516+ Object . keys ( ErrorCodes ) . find ( ( key ) => err . includes ( key ) ) ?? null ;
517+
518+ if ( ! errorKey ) return ;
519+
520+ return new IntegrationError ( ErrorCodes [ errorKey as keyof typeof ErrorCodes ] , {
521+ type : 'client' ,
522+ cause : error ,
523+ // We don't want to alert on these because
524+ // they are known issues/errors
525+ alert : false ,
526+ } ) ;
527+ }
You can’t perform that action at this time.
0 commit comments