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.

errorStatus and Status are not comparable

See original GitHub issue

The example for ErrorHandling in the readme does not work, stating that Type 'Status.NotFound' is not comparable to type 'ErrorStatus'.

This is the said part of the readme

app.use(async (ctx, next) => {
  try {
    await next();
  } catch (err) {
    if (isHttpError(err)) {
      switch (err.status) {
        case Status.NotFound:
          // handle NotFound
          break;
        default:
        // handle other statuses
      }
    } else {
      // rethrow if you can't handle the error
      throw err;
    }
  }
});

The fix that I could come up with is not pretty and is to cast err.status as Status but that is only possible by casting into unknown first and then into Status

switch (err.status as unknown as Status) {

Am I missing something?

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:6

github_iconTop GitHub Comments

2reactions
kitsonkcommented, May 18, 2020

Ok, I think I fixed it in 47e88ac01f7055b5613589566283205a21e13d8a. Comparing err.status with Status should work. ErrorStatus is not a seperate enum anymore, just a type and there is the type guard isErrorStatus(status) which will help narrow the types.

1reaction
kitsonkcommented, May 17, 2020

I should make this clearer in the documentation

Read more comments on GitHub >

github_iconTop Results From Across the Web

Attempting to create a WebAppHostNameBindingSlot ... - GitHub
Message that results from attempts to run is "Service returned an error. Status=<nil> <nil>". I have tried running in diagnostic mode, debug ...
Read more >
extracting the error status/message from POST call in angular
I have a POST call to rest api from my angular service, and I want to return either the error status or the...
Read more >
How to determine Warning or Error status based on gridview ...
I have a gridview with column named "Maturity Date". We need to send warning and error notification based on the "maturity Date".
Read more >
A Complete Guide and List of HTTP Status Codes
The request ultimately may or may not result in a completed response. 203: “Non-Authoritative Information.” This status code may appear when a ...
Read more >
Error Cluster data type - LabVIEW Wiki
Some information on it may be out of date, and should not be relied on ... LabVIEW Cluster that is used to contain...
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