Skip to content

Instantly share code, notes, and snippets.

@pjambet
Last active January 5, 2020 00:44
Show Gist options
  • Save pjambet/b4459f8f189f6e3f59087036b6dd0b30 to your computer and use it in GitHub Desktop.
Save pjambet/b4459f8f189f6e3f59087036b6dd0b30 to your computer and use it in GitHub Desktop.
Exeception handling in the controller
case Failure(exception) =>
exception match {
case e: CardException =>
complete(
StatusCodes.PaymentRequired,
HttpEntity(
ContentTypes.`application/json`,
"{\"message\": \"Invalid card\", \"code\": \"" + e.declineCode + "\"}"))
case _ =>
system.log.error(exception, "Unexpected error")
complete(
StatusCodes.InternalServerError,
HttpEntity(ContentTypes.`application/json`,
"{\"message\": \"Something went wrong\"}"))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment