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

Micro-package containing functions for handling an internal API error

Notifications You must be signed in to change notification settings

HugoPhibbs/handle-api-error

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

handle-api-error

  • Micro package for handling api errors. Provides simple function to help with debugging errors within APIs

Installation

npm install handle-api-error

Usage

const handleApiError = require('handle-api-error');

try {
    // Do something
} catch {
    throw handleApiError(error, "Doing something", 506, true); // Returns an error 
}

API

handleApiError(error, message, statusCode, expose)

  • Handles an API error.

Params:

  • error: Error that has been caught, that will be handled
  • message: String message to be displayed in the error
  • statusCode: Number status code to be displayed in the error, corresponds to a HTTP status code, default 400
  • expose: Boolean if the error should be exposed to the user, default true

About

Micro-package containing functions for handling an internal API error

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published