Mark
Mark

Reputation: 2061

how to Throw a customize http error in Scala Lagom

I know how to throw a bad request in Lagom by using

throw BadRequest("Bad Request")

but this will return with an http error code of 400. how do I return with a http error code of 409 (Conflict) for example?

Upvotes: 0

Views: 364

Answers (1)

Vladislav Kievski
Vladislav Kievski

Reputation: 1647

You need to create your custom exception that must be inherited from TransportException:

val ConflictErrorCode: TransportErrorCode = TransportErrorCode(409, -1003, "Conflict")

final class Conflict(message: String)
    extends TransportException(ConflictErrorCode, new ExceptionMessage(ConflictErrorCode.description, message))

Then in your code, you need to write:

throw new Conflict("Some conflict message")

Upvotes: 1

Related Questions