Comments (9)
Whether you use middleware? Im handling errors by error-middleware
const errorMiddleware{
name: "custom-errors",
error: (payload) => {
/ * operations with payload * /
return "something, that will given to your error in catch/error";
}
}
and replacing default error middleware when im define it
jsonApi.replaceMiddleware("errors", errorMiddleware);
from devour-client.
Hmm, that's strange – I'm pretty certain that the catch
callback should be getting passed the error.
One thing you should do is ensure that your API is responding with the correct error format outlined in the specification here: http://jsonapi.org/examples/#error-objects
Short of that, you could drop in your own custom error middleware and start debugging from that. You can find a basic example of that in the docs: https://github.com/twg/devour#your-first-middleware
from devour-client.
There is definitely an issue, the error itself is not passed to catch.
from devour-client.
Try to use this:
const { response, error } = jsonApi.create(...).then(response => ({ response }))
.catch(error => ({ error }))
from devour-client.
I have tried it, it would catch an error but not the actual error object with all the information. It would catch just a general error.
from devour-client.
The latest release (2.0) has some new code that might help resolve this issue in a more graceful manner. Let us know 👍
from devour-client.
I was proceeding like ViktorChernyaev using the old version. Upgrading to 2.0 does not resolve the errors handling at all.
Payload returned by the function called:
`{
"errors": [{
"code": "unprocessable_entity",
"detail": "Name has already been taken",
"meta": {
"attribute": "name",
"message": "has already been taken"
},
"source": {
"pointer": "/data/attributes/name"
},
"status": "422",
"title": "Validation Error"
}]
}`
Payload returned by the devour-client:
Error: Request failed with status code 422 at createError (createError.js?16d0:16) at settle (settle.js?db52:18) at XMLHttpRequest.handleLoad (xhr.js?ec6c:77)
Is there something wrong in the errors payload returned by the API? Can you please help to get the full errors payload?
from devour-client.
Hmmm, I don't have time to look into this myself, but that is unfortunate. If anyone is feeling brave enough to sort this out and send in a PR I'm more than happy to get this merged and published.
from devour-client.
Ok, to make it work properly you just need to replace
return buildErrors(payload.response.data);
with
return buildErrors(payload.response.data.errors);
in your javascript file res-errors.js
from devour-client.
Related Issues (20)
- Including recursive relationships result in null object
- The middleware does not exist HOT 8
- "Included" related resources are wiped if server does not support compound documents
- Is this project dead? HOT 2
- Improve Documentation HOT 1
- How to handle refresh Token HOT 2
- TypeScript type definitions HOT 4
- Way to consume relationships on the fly ? HOT 2
- `get` does not add model to req object HOT 2
- Congratulations and questions HOT 2
- Support for relationship metadata deserialization
- The example under Quick Start in the README confusingly uses "post"
- Please consider using release notes
- Add option to specify log level
- Update axios package to > 0.21.1 to solve security vulnerability HOT 14
- move CI to either travis-ci.com or github actions HOT 2
- Cross check JSON:API 1.1 compatibility
- Move devour to its own GitHub Org HOT 13
- API resource definition for model "foo" not found.
- Missing Relationship Function: DELETE HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from devour-client.