Skip to content
This repository has been archived by the owner on Mar 10, 2024. It is now read-only.

feat: better errors for outreach, return gateway timeouts to client #2057

Merged
merged 1 commit into from
Dec 12, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 40 additions & 8 deletions packages/core/remotes/impl/outreach/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import {
BadRequestError,
ConflictError,
ForbiddenError,
GatewayTimeoutError,
InternalServerError,
NotFoundError,
RemoteProviderError,
Expand Down Expand Up @@ -1964,22 +1965,53 @@ class OutreachClient extends AbstractEngagementRemoteClient {
const jsonError = err.response?.data?.errors?.[0];
const cause = err.response?.data;
const status = err.response?.status;
const errorMessage = jsonError?.title ?? err.cause?.message ?? err.message;

switch (status) {
case 400:
return new InternalServerError(jsonError?.title, { cause, origin: 'remote-provider', status });
return new InternalServerError(errorMessage, {
cause,
origin: 'remote-provider',
status,
});
case 401:
return new UnauthorizedError(jsonError?.title, { cause, origin: 'remote-provider', status });
return new UnauthorizedError(errorMessage, {
cause,
origin: 'remote-provider',
status,
});
case 403:
return new ForbiddenError(jsonError?.title, { cause, origin: 'remote-provider', status });
return new ForbiddenError(errorMessage, {
cause,
origin: 'remote-provider',
status,
});
case 404:
return new NotFoundError(jsonError?.title, { cause, origin: 'remote-provider', status });
return new NotFoundError(errorMessage, {
cause,
origin: 'remote-provider',
status,
});
case 409:
return new ConflictError(jsonError?.title, { cause, origin: 'remote-provider', status });
return new ConflictError(errorMessage, {
cause,
origin: 'remote-provider',
status,
});
case 422:
return new UnprocessableEntityError(jsonError?.title, { cause, origin: 'remote-provider', status });
return new UnprocessableEntityError(errorMessage, {
cause,
origin: 'remote-provider',
status,
});
case 429:
return new TooManyRequestsError(jsonError?.title, { cause, origin: 'remote-provider', status });
return new TooManyRequestsError(errorMessage, {
cause,
origin: 'remote-provider',
status,
});
case 504:
return new GatewayTimeoutError(errorMessage, { cause, status });
// The following are unmapped to Supaglue errors, but we want to pass
// them back as 4xx so they aren't 500 and developers can view error messages
case 402:
Expand Down Expand Up @@ -2027,7 +2059,7 @@ class OutreachClient extends AbstractEngagementRemoteClient {
case 449:
case 450:
case 451:
return new RemoteProviderError(jsonError?.title, { cause, status });
return new RemoteProviderError(errorMessage, { cause, status });
default:
return err;
}
Expand Down