Provides error class that should be thrown when you want to surface specific error codes via the api. CLIENT_ERROR & SERVER_ERROR and it's subclasses all extend the javascript Error object and so include stack traces to where the error was created, which makes debugging failure responses much easier. CLIENT_ERROR & SERVER_ERROR contains a status and a message, which are both returned to the client by the @chilangolabs/api error handling middleware.
require('@chilangolabs/api-errors/client')
CLIENT_ERROR- Generic API error, constructed with both a status message, all following errors extend this errorCLIENT_BAD_REQUEST- Status set to 400 and has a default message that can be overriddenCLIENT_UNAUTHORIZED- Status set to 401 and has a default message that can be overriddenCLIENT_INVALID_TOKEN- Status set to 400 and has a default message that can be overriddenCLIENT_FORBIDDEN- Status set to 403 and has a default message that can be overriddenNOT_FOUND- Status set to 404 and has a default message that can be overridden
require('@chilangolabs/api-errors')
SERVER_ERROR- Generic API error, constructed with both a status message, all following errors extend this errorDB_ERROR- Status set to 500 and has a default message that can be overriddenS3_ERROR- Status set to 500 and has a default message that can be overridden
require('@chilangolabs/api-errors/bot')
MESSENGER_ERROR- Status set to 500 and has a default message that can be overriddenTELEGRAM_ERROR- Status set to 500 and has a default message that can be overriddenWHATSAPP_ERROR- Status set to 500 and has a default message that can be overridden
require('@chilangolabs/api-errors/communication')
FIREBASE_ERROR- Status set to 500 and has a default message that can be overriddenSENDGRID_ERROR- Status set to 500 and has a default message that can be overriddenSES_ERROR- Status set to 500 and has a default message that can be overriddenTWILIO_ERROR- Status set to 500 and has a default message that can be overridden
require('@chilangolabs/api-errors/payment')
CONEKTA_ERROR- Status set to 500 and has a default message that can be overriddenOPENPAY_ERROR- Status set to 500 and has a default message that can be overriddenPAYPAL_ERROR- Status set to 500 and has a default message that can be overriddenSTRIPE_ERROR- Status set to 500 and has a default message that can be overridden
Return a 500 error when a prisma call fails
const { SERVER_ERROR } = require('@chilangolabs/api-errors'); try { const allUsers: User[] = await prisma.users(); } catch (e) { throw new SERVER_ERROR(); }