How do I redirect Exception to an error page?

Asked

Viewed 101 times

0

How do I redirect Usernamenotfoundexception to a page?

if ( user == null ) {
   log.info( "Email " + email + " não é um ususário cadastrado." );
   throw new UsernameNotFoundException( "Email " + email + " não é um ususário cadastrado." );
}

I guess I was not very clear in my question, Spring returns an error page, with the following message:

Whitelabel Error Page

This application has no Explicit Mapping for /error, so you are Seeing this as a fallback.

Mon Jul 31 15:20:43 BRT 2017 There was an Unexpected error (type=Forbidden, status=403). Access Denied

I would like the error message to be set via an HTML page created by me.

I’m using Angularjs with Spring, how do I map this?

1 answer

0

Add the property Authentication-Failure-url to your spring-security configuration xml

Example:

<form-login login-page="/"
        login-processing-url="/login"
        username-parameter="username"
        password-parameter="password" 
        default-target-url="/userhome" 
        always-use-default-target="true"
        authentication-failure-url="/error" 
         />

Browser other questions tagged

You are not signed in. Login or sign up in order to post.