[2.4.x-Java] ErrorHandler

37 views
Skip to first unread message

Enrico Morelli

unread,
Feb 11, 2016, 8:28:34 AM2/11/16
to play-framework
I follow the documentation instructions to enable ErrorHandler, but seems not working.

I created a ErrorHandler.java under app/controllers like that:

package controllers;

import play.http.HttpErrorHandler;
import play.mvc.*;
import play.mvc.Http.*;
import play.libs.F.*;

public class ErrorHandler implements HttpErrorHandler {
   
public Promise<Result> onClientError(RequestHeader request, int statusCode, String message) {
       
return Promise.<Result>pure(
               
Results.status(statusCode, "A client error occurred: " + message)
       
);
   
}

   
public Promise<Result> onServerError(RequestHeader request, Throwable exception) {
       
return Promise.<Result>pure(
               
Results.internalServerError("A server error occurred: " + exception.getMessage())
       
);
   
}
   
}


I tried to put play.http.HttpErrorHandler = "ErrorHandler" in application.conf, without result.

My question is, how it should working?

If I try a link with a wrong action , now I receive

Action not found


if the ErrorHandler works the "action not found"  is intercepted by onClientError or not.

When I'm sure that ErrorHandler works?


I'm little confused.

Enrico Morelli

unread,
Feb 11, 2016, 8:42:02 AM2/11/16
to play-framework
Solved putting play.http.errorHandler = "controllers.ErrorHandler" in the application.conf file.
Reply all
Reply to author
Forward
Message has been deleted
0 new messages