jfu jfu - 6 months ago 76
Scala Question

Error handling in play framework

I am developing a REST API using play framework. I would like to implement a centralized error handling for all my actions.

What is the best way to achieve this?


You should have a look at the GlobalSettings: https://www.playframework.com/documentation/2.3.x/ScalaGlobal

Especially, it allows you to override:

def onError(request: RequestHeader, ex: Throwable)
def onHandlerNotFound(request: RequestHeader)
def onBadRequest(request: RequestHeader, error: String)

onError is probably the one you are looking for, but the others may be useful too :)