Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Errors #20

Open
snovak7 opened this issue Oct 11, 2015 · 5 comments
Open

Errors #20

snovak7 opened this issue Oct 11, 2015 · 5 comments

Comments

@snovak7
Copy link

snovak7 commented Oct 11, 2015

How do you render/trigger errors, when they happen? This is also in JSON API 1.0 specification.

@jede
Copy link
Contributor

jede commented Oct 12, 2015

Right now this isn't handled by YAYSON. It would be great to get it in there though! If you would like to write a pull request that would be much appriciated :)

@snovak7
Copy link
Author

snovak7 commented Oct 12, 2015

Yes, there are then many options to consider, http response codes are involved here, so you need at least response object, which then can handle these, YAYSON doesn't even bother with content types as a quick browse through the code, but specification is quite explicit about it. But the most easy variant would be to "add errors", and then render would see if there are errors, then render error instead of the data, depends how deep you want to integrate it as a generic solution, or just as a quick serialisation to the user.

@jede
Copy link
Contributor

jede commented Oct 16, 2015

Yeah, so YAYSON is built so you can transport your data as you wish. So we use it over websockets for instance. Maybe some kind of error presenter is the way to go?

@jede
Copy link
Contributor

jede commented Feb 8, 2016

How would you like to use an ErrorPresenter? Ive been thinking about adding one. Here is the full spec: http://jsonapi.org/format/#errors

I guess it makes sense that you inherit from the ErrorPresenter and there you specify the bout link for instance? And I guess the rest is just common attributes?

@jlfama
Copy link

jlfama commented Feb 9, 2016

For my use case, I ended up checking if the response is an error when I receive it. If it is an error I return the error, if it isn't an error, I run it through YAYSON.

  // Coffeescript, AngularJS
  responseHandler = (data) ->
    dataParsed = JSON.parse(data)
    if _.has(dataParsed, 'errors')
      return dataParsed
    Store = yayson().Store
    store = new Store()
    model = store.sync(dataParsed)
    return model

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants