Skip to content

Need to check for status code  #17

@martyall

Description

@martyall

In the definition of HasMethodClients method r JSON (Aff (Either JSONClientError r)) (here) you are not checking the status code before deciding whether to parse the body of the request:

instance hasMethodClientMethodJson
  :: (DecodeJson r, IsSymbol method)
  => HasMethodClients method r JSON (Aff (Either JSONClientError r)) where
  getMethodClients method _ req = do
    toAffjaxRequest req
      # _ { method = toMethod method, responseFormat = AXResponseFormat.json }
      # request
      # map (bimap RequestError (_.body >>> decodeJson >>> lmap DecodeError) >>> join)

In the event that the networkl request succeeds but the server returns a non 200 response code, you are attempting to parse the body as valid a valid JSON for the type r, which is probably not what you want to do. IMO the correct implementation would define some kind of client error type in the event of non 200 similar to servant-client

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions