2
votes

Currently, if I access to non-defined path on my play framework application, default "Action Not Found page" appears. I tried to make custom "Action Not Found page" in order not to show system information on browser.

I checked the page.

https://www.playframework.com/documentation/2.4.x/JavaErrorHandling

And I implemented the following code.

package controllers;

import play.Logger;
import play.http.HttpErrorHandler;
import play.mvc.*;
import play.mvc.Http.*;
import play.libs.F.*;
import views.html.*;

public class ErrorHandler implements HttpErrorHandler {
    public Promise<Result> onClientError(RequestHeader request, int statusCode, String message) {
        Logger.debug("onClientError");
        return Promise.<Result> pure(
                Results.badRequest(error.render())
        );
    }

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

However error.scala.html isn't shown and default "Action Not Found page" appears. Logger.debug also wasn't called.

I found same question for Scala, but there isn't any answer.

How to handle "Action not found" with Dependency Injection Play framework 2.4

Could you give me any advice?

1

1 Answers

3
votes

I solved this problem by myself! I noticed that I should add ErrorHandler.java to default package or add to another package and write its class path to application.conf like this.

play.http.errorHandler = "com.example.ErrorHandler"

Thank you for your support!