6.3.3. OnErrors Interceptor

Interceptor that returns a specified response when an exception occurs in a business action. Responses can be specified for multiple exceptions.

This interceptor is enabled by configuring OnErrors to the business action method.

6.3.3.2. Module list

<dependency>
  <groupId>com.nablarch.framework</groupId>
  <artifactId>nablarch-fw-web</artifactId>
</dependency>

6.3.3.3. Using OnErrors

OnErrors annotation is configured for the method that processes the request in the business action.

OnError is used to specify the response to each exception.

An implementation example in which the following exceptions are thrown in the business action method is shown.

  • ApplicationException (Business error)
  • AuthenticationException (Authentication error)
  • UserLockedException (Account locked error. Subclass of AuthenticationException)
@OnErrors({
        @OnError(type = UserLockedException.class, path = "/WEB-INF/view/login/locked.jsp"),
        @OnError(type = AuthenticationException.class, path = "/WEB-INF/view/login/index.jsp"),
        @OnError(type = ApplicationException.class, path = "/WEB-INF/view/login/index.jsp")
})
public HttpResponse handle(HttpRequest request, ExecutionContext context) {
    // Business process is omitted
}

Important

Since the exceptions are processed in the order defined by OnError, the exceptions of subclasses must be defined first when defining exceptions that have an inheritance relationship.