Search in sources :

Example 1 with ReportPortalExceptionResolver

use of com.epam.ta.reportportal.commons.exception.rest.ReportPortalExceptionResolver in project service-authorization by reportportal.

the class WebMvcConfig method configureHandlerExceptionResolvers.

@Override
public void configureHandlerExceptionResolvers(List<HandlerExceptionResolver> exceptionResolvers) {
    RestErrorDefinition<Exception> authErrorDefinition = new RestErrorDefinition<>(HttpStatus.BAD_REQUEST, ErrorType.ACCESS_DENIED, new DefaultExceptionMessageBuilder());
    Map<Class<? extends Throwable>, RestErrorDefinition> errorMappings = ImmutableMap.<Class<? extends Throwable>, RestErrorDefinition>builder().put(OAuth2Exception.class, authErrorDefinition).put(AuthenticationException.class, authErrorDefinition).put(UsernameNotFoundException.class, authErrorDefinition).putAll(ExceptionMappings.DEFAULT_MAPPING).build();
    RestExceptionHandler handler = new RestExceptionHandler();
    handler.setOrder(Ordered.HIGHEST_PRECEDENCE + 1);
    handler.setErrorResolver(new ReportPortalExceptionResolver(new DefaultErrorResolver(errorMappings)));
    handler.setMessageConverters(messageConverters.getConverters());
    exceptionResolvers.add(handler);
}
Also used : DefaultExceptionMessageBuilder(com.epam.ta.reportportal.commons.exception.message.DefaultExceptionMessageBuilder) ReportPortalExceptionResolver(com.epam.ta.reportportal.commons.exception.rest.ReportPortalExceptionResolver) RestExceptionHandler(com.epam.ta.reportportal.commons.exception.rest.RestExceptionHandler) RestErrorDefinition(com.epam.ta.reportportal.commons.exception.rest.RestErrorDefinition) AuthenticationException(org.springframework.security.core.AuthenticationException) DefaultErrorResolver(com.epam.ta.reportportal.commons.exception.rest.DefaultErrorResolver) UsernameNotFoundException(org.springframework.security.core.userdetails.UsernameNotFoundException) OAuth2Exception(org.springframework.security.oauth2.common.exceptions.OAuth2Exception) AuthenticationException(org.springframework.security.core.AuthenticationException)

Aggregations

DefaultExceptionMessageBuilder (com.epam.ta.reportportal.commons.exception.message.DefaultExceptionMessageBuilder)1 DefaultErrorResolver (com.epam.ta.reportportal.commons.exception.rest.DefaultErrorResolver)1 ReportPortalExceptionResolver (com.epam.ta.reportportal.commons.exception.rest.ReportPortalExceptionResolver)1 RestErrorDefinition (com.epam.ta.reportportal.commons.exception.rest.RestErrorDefinition)1 RestExceptionHandler (com.epam.ta.reportportal.commons.exception.rest.RestExceptionHandler)1 AuthenticationException (org.springframework.security.core.AuthenticationException)1 UsernameNotFoundException (org.springframework.security.core.userdetails.UsernameNotFoundException)1 OAuth2Exception (org.springframework.security.oauth2.common.exceptions.OAuth2Exception)1