Skip to content

Commit 0792ebe

Browse files
authored
feat: ignore 502 gateway errors from apollo (#309)
1 parent fb79e41 commit 0792ebe

File tree

2 files changed

+39
-3
lines changed

2 files changed

+39
-3
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
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",

src/platforms/apollo/client.ts

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@ import {
33
formatUrl,
44
makeRequestFactory,
55
} from '@/sdk/client';
6+
import { IntegrationError } from '@/sdk/error';
67
import * as custom from '@/sdk/validators';
7-
import { objectify, shake } from 'radash';
8+
import { crush, guard, objectify, shake } from 'radash';
89
import { z } from 'zod';
910
import { BASE_URL, DEFAULT_PAGE_SIZE } from './constants';
1011
import {
@@ -55,7 +56,7 @@ const request = makeRequestFactory(async (auth, options) => {
5556
}
5657
: undefined,
5758
};
58-
});
59+
}, errorMapper);
5960

6061
export 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+
}

0 commit comments

Comments
 (0)