Search code examples
javaglobalinvokeplayframework-2.2onerror

playframework invoke onError method inside Globaj.java object


I am working with global object in Playframework. I've already created methods:

  • onHandlerNotFound (to invoke I have to enter address which is unhandled in routes)
  • onBadRequest to invoke I have to enter address with wrong time parameter, like: Users/edit/t. Method to edit user expects f.e. integer. It can't handle string

I've created method onError:

    public Promise<SimpleResult> onError(RequestHeader request, Throwable t) {
        Logger.error("Request: " + request + "generated error: " + t.toString());
        return Promise.<SimpleResult>pure(internalServerError(
            views.html.errorPage.render("500", "Errors occured")
        ));
    }

But I would like to test it. Please tell me how can I invoke this method to test it?


Solution

  • Create entry in routes file:

    GET /testOnError controllers.ErrorController.testOnError

    Error controller:

        public static Result testOnError() {
             throw new IllegalArgumentException();
        }
    

    Navigate to:

    http://HOST:PORT/testOnError