Add error container for API response failures
See original GitHub issueGiven the following example:
commerce.checkout.capture().error(error => this.handleError);
The error object looks like this (in the console):
error
Error: Request failed with status code 422
at createError (bundle.js:1968)
at settle (bundle.js:2214)
at XMLHttpRequest.handleLoad (bundle.js:1481)
The network response is this:
{"error":{"type":"not_valid","message":"Requested quantity not available"},"status_code":422}
In order to get that message, you must use error.response.data.error.message
(via Axios). This is a pretty verbose way to get the message from our response, which is a standardised structure from the API.
Perhaps we should wrap these errors in our own container class with easier access to the response data?
Issue Analytics
- State:
- Created 4 years ago
- Comments:5 (5 by maintainers)
Top Results From Across the Web
API failure reasons - Amazon Elastic Container Service
When an API action that you have triggered through the Amazon ECS API, console, or the AWS CLI exits with a failures error...
Read more >REST API Error Handling Best Practices
I believe that the best solution to handle errors in a REST API web services is the third option, in short: Use three...
Read more >How to Fix and Debug Docker Containers Like a Superhero
Container errors are tricky to diagnose, but some investigative magic works wonders. Read along to learn how to debug Docker containers.
Read more >Error handling in Azure API Management policies
Learn how to respond to error conditions that may occur during the processing of requests in Azure API Management.
Read more >HTTP status and error codes for JSON | Cloud Storage
The following document provides reference information about the status codes and error messages that are used in the Cloud Storage JSON API.
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 FreeTop 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
Top GitHub Comments
I was thinking the code would look like this:
End goal is that we have a nicer API for errors from our API, but you can still access the original error if need be.
I like the idea of doing a little error handling ourselves. I’m thinking we can create our own error class and make the errors thrown match something like this:
Should be pretty easy to implement.