Skip to content

Commit

Permalink
feat(rest-adapter): adds error map
Browse files Browse the repository at this point in the history
  • Loading branch information
rafamel committed Oct 24, 2019
1 parent 75d9534 commit 1e59d01
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions packages/rest-adapter/src/helpers/map-error.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { ErrorCode, PublicError } from '@karmic/core';

export const hash: { [P in ErrorCode]: number } = {
// Client
ClientError: 400,
ClientUnauthorized: 401,
ClientForbidden: 403,
ClientNotFound: 404,
ClientConflict: 409,
ClientUnsupported: 406,
ClientTooEarly: 425,
ClientRateLimit: 429,
// Server
ServerError: 500,
ServerNotImplemented: 501,
ServerGateway: 502,
ServerUnavailable: 503,
ServerTimeout: 504
};

export default function mapError(
error: PublicError,
serverError: PublicError
): { error: PublicError; status: number } {
const status = hash[error.code];

return status ? { error, status } : { error: serverError, status: 500 };
}

0 comments on commit 1e59d01

Please sign in to comment.