question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Currently koa seems to only handle standard code.

When i use a code like 420 with ctx.throw('custom message', 420) , koa replace it by a 500. When i use …

const err = new Error('custom message');
err.status = 420;
err.expose = true;
throw err;

… koa throw the error invalid status code: 420

I need to use custom code. Is there a way to add custom code to koa ?

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
ghostcommented, Mar 3, 2017

so good answer is

let statuses = require('koa/node_modules/statuses')
statuses['700'] = 'custom status';
ctx.throw(700);

Would be usefull to give access to statuses in app

0reactions
PlasmaPowercommented, Mar 3, 2017

Look at the tests here: https://github.com/koajs/koa/blob/master/test/response/status.js

statuses['700'] = 'custom status';
Read more comments on GitHub >

github_iconTop Results From Across the Web

Can we create custom HTTP Status codes? - Stack Overflow
Yes, as long as you respect the class -- that is, 2xx for success, 4xx for Client error, etc. So you can return...
Read more >
List of HTTP status codes - Wikipedia
This is a list of Hypertext Transfer Protocol (HTTP) response status codes. Status codes are ... Custom error pages · List of FTP...
Read more >
HTTP response status codes - MDN Web Docs - Mozilla
HTTP response status codes indicate whether a specific HTTP request has been successfully completed. Responses are grouped in five classes:
Read more >
A Complete Guide and List of HTTP Status Codes
Understanding HTTP Status Code Classes · 100s: Informational codes indicating that the request initiated by the browser is continuing. · 200s: ...
Read more >
How to return a custom HTTP status code using WebAPI 2
This post will give you an example on how to return such a custom HTTP code. Have a look here for the natively...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found