com.ugam.collage.plus.controller.ExceptionHandlerController.java Source code

Java tutorial

Introduction

Here is the source code for com.ugam.collage.plus.controller.ExceptionHandlerController.java

Source

/**
 * Class Name:         ExceptionHandlerController
 *
 * Created By:         Rishi.c2
 * Created On:         8:06:49 PM, Sep 20, 2014
 *
 * Modified By:         Rishi.c2
 * Modified On:         8:06:49 PM, Sep 20, 2014
 *
 * Description:
 *
 * Copyright (c) 2013 Ugam Interactive. All rights reserved.
 *
 * Use is subject to license terms.
 */

package com.ugam.collage.plus.controller;

import org.springframework.http.HttpStatus;
import org.springframework.security.access.AccessDeniedException;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseStatus;

@ControllerAdvice
public class ExceptionHandlerController {

    @ResponseStatus(HttpStatus.NOT_FOUND)
    class ResourceNotFoundException extends RuntimeException {

        private static final long serialVersionUID = 1L;
    }

    @ResponseStatus(HttpStatus.BAD_REQUEST)
    class BadGatewayException extends RuntimeException {

        private static final long serialVersionUID = 1L;
    }

    @ResponseStatus(HttpStatus.NOT_FOUND)
    public String resourceNotFoundException() {

        return "error-bad-request";
    }

    @ExceptionHandler(BadGatewayException.class)
    public String badGatewayException(BadGatewayException e) {

        return "error-bad-request";
    }

    @ExceptionHandler(AccessDeniedException.class)
    public String accessDeniedException(AccessDeniedException e) {

        return "error-not-authorized";
    }

}