Skip to content

Unhelpful exceptions thrown when performing requests #59

@AndyHWChung

Description

@AndyHWChung

When performing http requests, it is difficult to obtain the response body and headers if the status is not 2xx. The exceptions thrown if the response is not 2xx only contain a message String. The only way to obtain the response body is to possibly perform some regex on the message to extract it out. What would be nicer if a user was able to write something like this:

http.POST(url, body).map{ response: HttpResponse =>
  response.status match {
    case 200 => /** do something */
    case 401 => /** do something else */
    ... 
  }
}

This is impossible however as exception are being thrown before we get the map in the example above. Doing this:

http.POST(url, body).recover{
  case e: BadRequestException => /** do something */
}

is problematic as the exception only contains a message String. There is no easy way of using the body of the response during error handling.

Could the code be refactored so it doesn't throw exceptions if it's returning a HttpResponse or can the exceptions be made to include more easily accessible information?

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