errorStatus and Status are not comparable
See original GitHub issueThe 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:
- Created 3 years ago
- Comments:6
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Ok, I think I fixed it in 47e88ac01f7055b5613589566283205a21e13d8a. Comparing
err.status
withStatus
should work.ErrorStatus
is not a seperate enum anymore, just a type and there is the type guardisErrorStatus(status)
which will help narrow the types.I should make this clearer in the documentation