Skip to content

nicolasespiau/app-error

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

AppError

Install

npm i -S @bonjourjohn/app-error

Usage

With koa:

const koa = require('koa');
const AppError = require('@bonjourjohn/app-error');

const app = new koa();

app.use(async (ctx, next) => {
  try {
    await next();
  } catch (err) {
    //if caught error is not AppError, convert it
    if (!(err instanceOf AppError)) {
      err = AppError.fromError(err);
    }

    // will only respond with JSON
    ctx.status = err.errno;
    ctx.body = {
      errno: err.errno,
      error: err.error
    };
  }
});

[...] //rest of your code

Testing

Run npm test after npm install.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published