Skip to content

Return error 400 if path part is invalid instead of 500 #56

Open
@gugu

Description

@gugu

Current behaviour:
curl corp.short.cm/%AF returns 500 Internal Server Error
Expected:
curl corp.short.cm/%AF returns 400 Invalid request

I'm running a link shortener service and user put different combinations in path part, some of them are valid, some of them - not. This case I sent is a client error and there is no need to raise an exception here

URIError: URI malformed
  ?, in decodeURIComponent
  File "/srv/shorturl_redirector/node_modules/koa-route/index.js", line 60, col 19, in decode
    if (val) return decodeURIComponent(val);
  ?, in Array.map
  File "/srv/shorturl_redirector/node_modules/koa-route/index.js", line 34, col 35, in null.<anonymous>
    const args = m.slice(1).map(decode);
  File "/srv/shorturl_redirector/node_modules/koa-compose/index.js", line 42, col 32, in dispatch
    return Promise.resolve(fn(context, dispatch.bind(null, i + 1)));
  File "/srv/shorturl_redirector/node_modules/koa-route/index.js", line 43, col 16, in null.<anonymous>
    return next();
  File "/srv/shorturl_redirector/node_modules/koa-compose/index.js", line 42, col 32, in dispatch
    return Promise.resolve(fn(context, dispatch.bind(null, i + 1)));
  File "/srv/shorturl_redirector/node_modules/koa-route/index.js", line 43, col 16, in null.<anonymous>
    return next();
  File "/srv/shorturl_redirector/node_modules/koa-compose/index.js", line 42, col 32, in dispatch
    return Promise.resolve(fn(context, dispatch.bind(null, i + 1)));
  File "/srv/shorturl_redirector/node_modules/koa-route/index.js", line 43, col 16, in null.<anonymous>
    return next();
  File "/srv/shorturl_redirector/node_modules/koa-compose/index.js", line 42, col 32, in dispatch
    return Promise.resolve(fn(context, dispatch.bind(null, i + 1)));
  File "/srv/shorturl_redirector/node_modules/koa-route/index.js", line 43, col 16, in null.<anonymous>
    return next();
  File "/srv/shorturl_redirector/node_modules/koa-compose/index.js", line 42, col 32, in dispatch
    return Promise.resolve(fn(context, dispatch.bind(null, i + 1)));
  File "/srv/shorturl_redirector/node_modules/koa-route/index.js", line 43, col 16, in null.<anonymous>
    return next();
  File "/srv/shorturl_redirector/node_modules/koa-compose/index.js", line 42, col 32, in dispatch
    return Promise.resolve(fn(context, dispatch.bind(null, i + 1)));
  File "/srv/shorturl_redirector/node_modules/koa-views/src/index.js", line 55, col 12, in views
    return next()
  File "/srv/shorturl_redirector/node_modules/koa-compose/index.js", line 42, col 32, in dispatch
    return Promise.resolve(fn(context, dispatch.bind(null, i + 1)));
  File "/srv/shorturl_redirector/node_modules/koa-body/index.js", line 110, col 14, in null.<anonymous>
    return next();
  File "internal/process/next_tick.js", line 68, col 7, in process._tickCallback

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions