Skip to content

Commit

Permalink
Fix the error message parser and add TwitterUnknownErrorResponse to T…
Browse files Browse the repository at this point in the history
…witterError.

The Twitter documentation says that the error response looks like this:

  {"errors":[{"message":"Sorry, that page does not exist","code":34}]}

However, Twitter occasionally responds error responses, formatted as an undocumented form, such as:

  {"errors":"...."}
  • Loading branch information
himura committed Oct 25, 2014
1 parent 15fe11e commit 48f90f6
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
4 changes: 3 additions & 1 deletion Web/Twitter/Conduit/Base.hs
Original file line number Diff line number Diff line change
Expand Up @@ -116,10 +116,12 @@ checkResponse :: Response Value
-> Either TwitterError Value
checkResponse Response{..} =
case responseBody ^? key "errors" of
Just errs ->
Just errs@(Array _) ->
case fromJSON errs of
Success errList -> Left $ TwitterErrorResponse responseStatus responseHeaders errList
Error msg -> Left $ FromJSONError msg
Just err ->
Left $ TwitterUnknownErrorResponse responseStatus responseHeaders err
Nothing ->
if sci < 200 || sci > 400
then Left $ TwitterStatusError responseStatus responseHeaders responseBody
Expand Down
1 change: 1 addition & 0 deletions Web/Twitter/Conduit/Response.hs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ data Response responseType = Response
data TwitterError
= FromJSONError String
| TwitterErrorResponse Status ResponseHeaders [TwitterErrorMessage]
| TwitterUnknownErrorResponse Status ResponseHeaders Value
| TwitterStatusError Status ResponseHeaders Value
deriving (Show, Typeable, Eq)

Expand Down

0 comments on commit 48f90f6

Please sign in to comment.