Skip to content

HttpPost methods can throw exceptions rather than returning failed Futures #104

@glidester

Description

@glidester

uk.gov.hmrc.http.HttpPost methods have a contract to return a Future response. However they can actually throw IllegalArgumentExceptions (rather that returning a failed Future as per their contract) if you pass an invalid 'url' String parameter to it.

Obviously you should not be passing invalid URLs to one of these methods but sometimes this is not within your control (when you get URLs from another service for instance).

It is very hidden that these methods can throw exceptions (which is itself very un-scala like) so it will catch out developers who are rightly expecting a Future to be returned.

One solution to this issue would be for these methods to accept a java.net.URL as the type of the 'url' parameter instead of String (thus enforcing the good url requirement via the type system). Obviously this would then change the signature of all the methods (or result in another set of methods with different signatures).

The alternate solution would be for the hmrc implementations of HttpPost to catch any such exceptions (caused by invalid url Strings) and return the exception in a failed Future (as per contract).

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