com.aquest.emailmarketing.web.controllers.ErrorHandler.java Source code

Java tutorial

Introduction

Here is the source code for com.aquest.emailmarketing.web.controllers.ErrorHandler.java

Source

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package com.aquest.emailmarketing.web.controllers;

import org.springframework.dao.DataAccessException;
import org.springframework.security.access.AccessDeniedException;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;

// TODO: Auto-generated Javadoc
/**
 * The Class ErrorHandler.
 */
@ControllerAdvice
public class ErrorHandler {

    /**
     * Handle database exception.
     *
     * @param ex the ex
     * @return the string
     */
    @ExceptionHandler(DataAccessException.class)
    public String handleDatabaseException(DataAccessException ex) {
        ex.printStackTrace();
        return "error";
    }

    /**
     * Handle access exception.
     *
     * @param ex the ex
     * @return the string
     */
    @ExceptionHandler(AccessDeniedException.class)
    public String handleAccessException(AccessDeniedException ex) {
        return "denied";
    }
}