{"action":"created","issue":{"url":"https://api.github.com/repos/NoRedInk/elm-rails/issues/7","labels_url":"https://api.github.com/repos/NoRedInk/elm-rails/issues/7/labels{/name}","comments_url":"https://api.github.com/repos/NoRedInk/elm-rails/issues/7/comments","events_url":"https://api.github.com/repos/NoRedInk/elm-rails/issues/7/events","html_url":"https://github.com/NoRedInk/elm-rails/pull/7","id":117228682,"number":7,"title":"Decoding server errors","user":{"login":"ento","id":21108,"avatar_url":"https://avatars.githubusercontent.com/u/21108?v=3","gravatar_id":"","url":"https://api.github.com/users/ento","html_url":"https://github.com/ento","followers_url":"https://api.github.com/users/ento/followers","following_url":"https://api.github.com/users/ento/following{/other_user}","gists_url":"https://api.github.com/users/ento/gists{/gist_id}","starred_url":"https://api.github.com/users/ento/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ento/subscriptions","organizations_url":"https://api.github.com/users/ento/orgs","repos_url":"https://api.github.com/users/ento/repos","events_url":"https://api.github.com/users/ento/events{/privacy}","received_events_url":"https://api.github.com/users/ento/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":2,"created_at":"2015-11-16T22:03:13Z","updated_at":"2015-11-19T23:02:34Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/NoRedInk/elm-rails/pulls/7","html_url":"https://github.com/NoRedInk/elm-rails/pull/7","diff_url":"https://github.com/NoRedInk/elm-rails/pull/7.diff","patch_url":"https://github.com/NoRedInk/elm-rails/pull/7.patch"},"body":"### Motivation\r\n\r\nWhen a Rails controller responds with a model with validation errors:\r\n\r\n```ruby\r\nrespond_with @model_with_validation_errors\r\n```\r\n\r\nit basically boils down to:\r\n\r\n```ruby\r\nrender json: {errors: model.errors},\r\n       status: :unprocessable_entity\r\n```\r\n\r\n(in the context of an ajax request that accepts JSON)\r\n(relevant source: https://github.com/rails/rails/blob/0c2854fa0302acfeb27f1316f2163b3c1dfc4f95/actionpack/lib/action_controller/metal/responder.rb#L264 )\r\n\r\n[A status of `:unprocessable_entity` is represented by status code 422](https://github.com/rails/rails/blob/0450642c27af3af35b449208b21695fd55c30f90/guides/source/layouts_and_rendering.md#the-status-option).\r\n\r\n`Rails.send` uses `Http.fromJson` internally, which [interprets status codes outside the 200 range as `BadResponse`.](https://github.com/evancz/elm-http/blob/64c1b15661841bed584bd40c3d4bd1103086eb2b/src/Http.elm#L430)\r\n\r\nThis PR adds a way to pull out the actual errors instead.\r\n\r\n### Backwards incompatible changes\r\n\r\n```elm\r\n-send : String -> Decoder value -> String -> String -> Http.Body -> Task Http.Error value\r\n-send authToken decoder verb url body =\r\n\r\n+get : String -> ResponseDecoder error value -> String -> Task (Error error) value\r\n+get authToken decoder url =\r\n\r\n+post : String -> ResponseDecoder error value -> String -> Http.Body -> Task (Error error) value\r\n+post authToken decoder url body =\r\n\r\n+send: String -> String -> String -> Http.Body -> Task Http.RawError Http.Response\r\n+send authToken verb url body =\r\n```\r\n\r\n### New stuff\r\n\r\n```elm\r\nRails.Error\r\nRails.get\r\nRails.post\r\nRails.fromJson\r\nRails.always\r\nRails.decoder\r\nRails.ResponseDecoder\r\n```\r\n"},"comment":{"url":"https://api.github.com/repos/NoRedInk/elm-rails/issues/comments/158227979","html_url":"https://github.com/NoRedInk/elm-rails/pull/7#issuecomment-158227979","issue_url":"https://api.github.com/repos/NoRedInk/elm-rails/issues/7","id":158227979,"user":{"login":"rtfeldman","id":1094080,"avatar_url":"https://avatars.githubusercontent.com/u/1094080?v=3","gravatar_id":"","url":"https://api.github.com/users/rtfeldman","html_url":"https://github.com/rtfeldman","followers_url":"https://api.github.com/users/rtfeldman/followers","following_url":"https://api.github.com/users/rtfeldman/following{/other_user}","gists_url":"https://api.github.com/users/rtfeldman/gists{/gist_id}","starred_url":"https://api.github.com/users/rtfeldman/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rtfeldman/subscriptions","organizations_url":"https://api.github.com/users/rtfeldman/orgs","repos_url":"https://api.github.com/users/rtfeldman/repos","events_url":"https://api.github.com/users/rtfeldman/events{/privacy}","received_events_url":"https://api.github.com/users/rtfeldman/received_events","type":"User","site_admin":false},"created_at":"2015-11-19T23:02:34Z","updated_at":"2015-11-19T23:02:34Z","body":"Looks awesome! Merging!"}}