koajs / bodyparser

Koa body parsing middleware
MIT License
1.31k stars 116 forks source link

add warning msg when parseBody, no enableTypes matched in koa-bodypar… #78

Closed i5ting closed 7 years ago

i5ting commented 7 years ago

…ser module

i5ting commented 7 years ago
 async function parseBody(ctx) {
    if (enableJson && ((detectJSON && detectJSON(ctx)) || ctx.request.is(jsonTypes))) {
      return await parse.json(ctx, jsonOpts);
    }
    if (enableForm && ctx.request.is(formTypes)) {
      return await parse.form(ctx, formOpts);
    }
    if (enableText && ctx.request.is(textTypes)) {
      return await parse.text(ctx, textOpts) || '';
    }
    return {};
  }

when no type matched, 'return {};', developer can't realised the mistake

dead-horse commented 7 years ago

it should return empty object when request type not match json, form or text.

i5ting commented 7 years ago

@dead-horse in co-body https://github.com/cojs/co-body/blob/master/lib/any.js#L44

when not matched will be reject an error code:415, which is right?

dead-horse commented 7 years ago

co-body is a independent module that you can determined which request should pass to co-body, but koa-bodyparser will handle all the requests, it shouldn't throw when type not match.