Socket
Socket
Sign inDemoInstall

inra-server-error

Package Overview
Dependencies
0
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    inra-server-error

[![npm](https://img.shields.io/npm/v/inra-server-error.svg?maxAge=2592000)](https://www.npmjs.com/package/inra-server-error) [![Dependency Status](https://david-dm.org/project-inra/inra-server.svg?path=packages/inra-server-error)](https://david-dm.org/pro


Version published
Maintainers
1
Install size
30.1 kB
Created

Readme

Source

inra-server-error

npm Dependency Status

A simple, yet powerful error handler shipped as a middleware for Koa. inra-server-error provides a set of utilities for defining and returning HTTP errors. Each utility returns an error response object which includes the following properties:

{
  "success": "…",
  "errorCode": "…",
  "userMessage": "…",
  "developerMessage": "…"
}

Note: full documentation with more examples is published on our Wiki. Please, refer to our Wiki for installation details and API references.

Installation

$ npm install --save inra-server-error

API

import error, {defineError} from "inra-server-error";

error(options)

Koa errors middleware which catches exceptions thrown inside other middlewares or routes and generates a graceful response.

Example:

app.use(error({
  errorCode: "Default error code"
  httpStatus: "Default HTTP status",
  userMessage: "Default user message",

  callback(error) {
    // Will be executed on each exception
  }
}));

defineError(definition)

Defines an error handler for a specified exception type.

Note: to make our middleware handle custom errors, you must define an error with exception's instance. Other fields are optional.

Example:

defineError({
  instance: AuthWrongUsernameError,
  errorCode: "Optional error code"
  httpStatus: "Optional HTTP status",
  userMessage: "Optional user message",

  callback(error) {
    // …
  }
});
class CustomError extends Error {
  errorCode = 103;
  httpStatus = 401;
  userMessage = "Something went wrong";
};

defineError({
  instance: CustomError
});

Contributing

Bug reporting

Github Open Issues Github Closed Issues Github Pull Requests

We want contributing to Inra Server to be fun, enjoyable, and educational for anyone, and everyone. Changes and improvements are more than welcome! Feel free to fork and open a pull request. If you have found any issues, please report them here - they are being tracked on GitHub Issues.

Development

We have prepared multiple commands to help you develop inra-server-error on your own. Don't forget to install all Node.js dependencies from npm. You will need a local copy of Node.js installed on your machine.

$ npm install
Usage
$ npm run <command>
List of commands
CommandDescription
buildBuilds inra-server-error
watchRe-builds inra-server-error on changes
cleanDeletes builds ands cache
lintFixes Lint errors
flowChecks Flow errors
testChecks Flow errors and runs tests

FAQs

Last updated on 15 May 2018

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc