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.

HTTP error if code in error NaN

See original GitHub issue

HTTP error if code in error NaN

After update to 20.. if server throw new Error() with code: NaN throws unhandled promise rejection. Logs:

(node:803571) UnhandledPromiseRejectionWarning: RangeError [ERR_HTTP_INVALID_STATUS_CODE]: Invalid status code: NaN                                                                                                  
    at ServerResponse.writeHead (_http_server.js:209:11)                                                                                                                                                             
    at WebServer.sendWithCompression (/project/node_modules/actionhero/servers/web.js:259:38)                                                                                              
    at WebServer.sendMessage (/project/node_modules/actionhero/servers/web.js:119:10)                                                                                                      
    at WebServer.completeResponse (/project/node_modules/actionhero/servers/web.js:394:10)                                                                                                 
    at process._tickCallback (internal/process/next_tick.js:68:7) 
  • ActionHero Version: 20.0.0
  • Node.js Version: 10.15.1
  • Operating System: Arch Linux

Steps to reproduce your error

  • Throw new Error with code: NaN

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:9 (9 by maintainers)

github_iconTop GitHub Comments

1reaction
evantahlercommented, Nov 2, 2019

I think I’m still confused about how you found this state. Can you please provide a sample action that reproduces this behavior?

If you were to make an error in an action with a non-intenger code, i.e.

error = new Error('nope')
error.code = 'not-a-number'
throw error

it would still fail the numeric range check https://github.com/actionhero/actionhero/blob/master/servers/web.js#L347-L363 and isValidCustomResponseCode would be false, so we would just return a HTTP status code of 500 (line 358)

0reactions
witemcommented, Nov 24, 2019

@evantahler seems all work fine. I can’t reproduce this error. Sorry and thanks

Read more comments on GitHub >

github_iconTop Results From Across the Web

JavaScript simple "error-handling" by replacing NaN with ...
I was wondering how I can detect false input type and instead of presenting the user with NaN, have a logical ...
Read more >
NaN - JavaScript - MDN Web Docs
To tell if a value is NaN , use Number.isNaN() or isNaN() to most clearly determine whether a value is NaN — or,...
Read more >
I am getting a NaN error. What does this mean? - Codecademy
Nan means “Not a number”, this is because inside your cube function, you're not calling the square function, but getting it's contents. Change...
Read more >
HTTP Status Codes: All 63 explained - including FAQ & Video
HTTP status codes are three-digit responses from the server to the browser-side request. Everyone has probably gotten the classic 404 page-not-found error.
Read more >
json.dumps allows NaN values in JSON by default, which is ...
... the API's parser can't process that, so the client will get back an HTTP 400 error if a NaN value is accidentally...
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