Code Monkey home page Code Monkey logo

Comments (9)

ViktorChernyaev avatar ViktorChernyaev commented on June 30, 2024 1

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.

Emerson avatar Emerson commented on June 30, 2024

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.

Maxoos avatar Maxoos commented on June 30, 2024

There is definitely an issue, the error itself is not passed to catch.

from devour-client.

superp avatar superp commented on June 30, 2024

Try to use this:

const { response, error } = jsonApi.create(...).then(response => ({ response }))
.catch(error => ({ error }))

from devour-client.

Maxoos avatar Maxoos commented on June 30, 2024

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.

Emerson avatar Emerson commented on June 30, 2024

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.

VinceBassman avatar VinceBassman commented on June 30, 2024

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.

Emerson avatar Emerson commented on June 30, 2024

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.

VinceBassman avatar VinceBassman commented on June 30, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.