Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

koa-bodyparser

Package Overview
Dependencies
Maintainers
1
Versions
30
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

koa-bodyparser - npm Package Compare versions

Comparing version 1.5.0 to 1.6.0

15

History.md
1.5.0 / 2015-04-04
1.6.0 / 2015-05-01
==================
* feat: support custom error handler
1.5.0 / 2015-04-04
==================
* Use an empty object instead of null, if no body is parsed
1.4.1 / 2015-03-10
1.4.1 / 2015-03-10
==================

@@ -12,3 +17,3 @@

1.4.0 / 2015-02-26
1.4.0 / 2015-02-26
==================

@@ -18,3 +23,3 @@

1.3.1 / 2015-01-27
1.3.1 / 2015-01-27
==================

@@ -24,3 +29,3 @@

1.3.0 / 2014-11-27
1.3.0 / 2014-11-27
==================

@@ -27,0 +32,0 @@

@@ -31,3 +31,6 @@ /**!

var detectJSON = opts.detectJSON;
var onerror = opts.onerror;
opts.detectJSON = undefined;
opts.onerror = undefined;
var jsonOpts = jsonOptions(opts);

@@ -54,12 +57,12 @@ var formOpts = formOptions(opts);

return function *bodyParser(next) {
if (this.request.body !== undefined) {
return yield* next;
}
if (this.request.body !== undefined) return yield* next;
if ((detectJSON && detectJSON(this)) || this.request.is(jsonTypes)) {
this.request.body = yield parse.json(this, jsonOpts);
} else if (this.request.is(formTypes)) {
this.request.body = yield parse.form(this, formOpts);
} else {
this.request.body = {};
try {
yield* parseBody(this);
} catch (err) {
if (onerror) {
onerror(err, this);
} else {
throw err;
}
}

@@ -69,2 +72,12 @@

};
function* parseBody(ctx) {
if ((detectJSON && detectJSON(ctx)) || ctx.request.is(jsonTypes)) {
ctx.request.body = yield parse.json(ctx, jsonOpts);
} else if (ctx.request.is(formTypes)) {
ctx.request.body = yield parse.form(ctx, formOpts);
} else {
ctx.request.body = {};
}
}
};

@@ -71,0 +84,0 @@

{
"name": "koa-bodyparser",
"version": "1.5.0",
"version": "1.6.0",
"description": "a body parser for koa",

@@ -5,0 +5,0 @@ "main": "index.js",

@@ -68,5 +68,12 @@ koa-bodyparser

```
* **onerror**: support custom error handle, if `koa-bodyparser` throw an error, you can customize the response like:
```js
app.use(bodyparser({
onerror: function (err, ctx) {
ctx.throw('body parse error', 422);
}
}));
```
## Licences
[MIT](LICENSE)
SocketSocket SOC 2 Logo

Product

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

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc