koa-custom-statuses
v1.5.2
Published
A tiny library to add or overwrite koa status codes allowing for custom status codes and status messages
Downloads
11
Maintainers
Readme
Koa Custom Statuses
Koa has a defined set of HTTP response codes that can be retured in a request. While they are shandard HTTP codes and will be enough most of the time, Sometimes, there is a need for creating custom codes. This module enables you to achieve just that declaring the additional codes you require in the very beginning. It also enables you to change the status message of existing status codes.
The module definition is extremely simple. Just wrap a koa function into the module along with an object containing the status code you require.
var koa = require('koa')
var app = koa()
require('koa-custom-statuses')(app, {
'200': 'Im Loving it!!',
'499': 'Cos I can come that close to 500',
'700': 'Theres the 7 series in HTTP',
'999': 'Because We can'
});
app.use(funcion(){
//This will no longer throw an invalid code error
this.status = 700;
})
There are just some basics you need to keep in mind.
- The status codes can be 3 digit numbers only.
- The codes you declare will overwrite the Koa Defaults.
- You can only use default Koa codes or the codes defined in the module. Any others will throw an error