Guest User

Untitled

a guest
Nov 17th, 2019
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Scala 0.69 KB | None | 0 0
  1.  def handleResponseWithRecover[T](response: Future[WSResponse], success: WSResponse => T): Future[T] = {
  2.     response.map { resp =>
  3.       if (!Status.isSuccessful(resp.status)) {
  4.         logger.warn(s"Error from ${serviceName} - status '${resp.status}' on '${resp.uri}' with body '${resp.body}' ")
  5.       }
  6.       success(resp)
  7.     }.recover {
  8.       case rse: RemoteServerException =>
  9.         logger.error(s"Error response from $serviceName - ${rse.error}", rse)
  10.         throw rse
  11.       case t: Throwable =>
  12.         logger.error(s"Internal server error when contacting $serviceName ${t.getMessage}", t)
  13.         throw InternalServerException("error.unexpected", s"${t.getMessage}", t)
  14.     }
  15.   }
Advertisement
Add Comment
Please, Sign In to add comment