Skip to content

Commit

Permalink
feat: ignore 502 gateway errors from apollo (#309)
Browse files Browse the repository at this point in the history
  • Loading branch information
sodiray authored Aug 30, 2023
1 parent fb79e41 commit 0792ebe
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 3 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@vesselapi/integrations",
"version": "1.0.76",
"version": "1.0.77",
"description": "Vessel integrations",
"main": "dist/index.js",
"module": "dist/index.mjs",
Expand Down
40 changes: 38 additions & 2 deletions src/platforms/apollo/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@ import {
formatUrl,
makeRequestFactory,
} from '@/sdk/client';
import { IntegrationError } from '@/sdk/error';
import * as custom from '@/sdk/validators';
import { objectify, shake } from 'radash';
import { crush, guard, objectify, shake } from 'radash';
import { z } from 'zod';
import { BASE_URL, DEFAULT_PAGE_SIZE } from './constants';
import {
Expand Down Expand Up @@ -55,7 +56,7 @@ const request = makeRequestFactory(async (auth, options) => {
}
: undefined,
};
});
}, errorMapper);

export const client = {
auth: {
Expand Down Expand Up @@ -489,3 +490,38 @@ export const client = {
},
passthrough: request.passthrough(),
};

const ErrorCodes = {
'502: Bad gateway': 'Bad gateway, apollo api did not respond',
};

const serializeError = (error: any) => {
return (
guard(() =>
JSON.stringify({
name: error.name,
message: error.message,
code: error.code,
stack: error.stack,
cause: error.cause,
...crush(error),
}),
) ?? `${error}`
);
};

function errorMapper(error: any) {
const err = serializeError(error);
const errorKey =
Object.keys(ErrorCodes).find((key) => err.includes(key)) ?? null;

if (!errorKey) return;

return new IntegrationError(ErrorCodes[errorKey as keyof typeof ErrorCodes], {
type: 'client',
cause: error,
// We don't want to alert on these because
// they are known issues/errors
alert: false,
});
}

0 comments on commit 0792ebe

Please sign in to comment.