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.

Polka always running onError handler

See original GitHub issue

I am using polka v0…5.0 and here is my code

import polka from 'polka';

const httpserver = polka({
        onError: (e) => {
          console.log('Error handling request');
          console.log(e);
           }
      });
 httpserver.get('/', (req, res) => {
      console.log('Request received');
      res.end('Hello World!');
    })
 httpserver.listen(3000, err => {
   if(err) {
    console.log(err);
   }
  })

When I access the route ‘/’, I can see “Request received” in terminal and “Hello world” in browser but Polka is also running onError handler each time I access ‘/’ route with error 404. Why polka is running onError handler even there is no un-handled exception in route handler.

Issue Analytics

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

github_iconTop GitHub Comments

1reaction
zolotokrylincommented, Jul 16, 2020

Thank you, Luke.

1reaction
lukeedcommented, Jul 15, 2020

Hi @zolotokrylin,

You’re creating an Error object but you never throw it. It’s like new Cat but never assigning it to a variable.

You should check out these docs for info

Read more comments on GitHub >

github_iconTop Results From Across the Web

polka - Bountysource
This happens because the first subapp responds with 404 (e.g. calls no match handler) and therefore doesn't switch to the next app, resulting...
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