All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.testerum.web_backend.controllers.error.ExceptionHandlerControllerAdvice.kt Maven / Gradle / Ivy

package com.testerum.web_backend.controllers.error

import org.springframework.web.bind.annotation.ControllerAdvice
import org.springframework.web.bind.annotation.ExceptionHandler
import org.springframework.web.servlet.ModelAndView
import org.springframework.web.util.WebUtils
import javax.servlet.http.HttpServletRequest

/**
 * When any exception is thrown by a controller method, this class is invoked and will do a forward to the [ErrorController].
 */
@ControllerAdvice
class ExceptionHandlerControllerAdvice {

    @ExceptionHandler(Exception::class)
    fun defaultErrorHandler(
        request: HttpServletRequest,
        e: Exception?
    ): ModelAndView {
        request.setAttribute(WebUtils.ERROR_EXCEPTION_ATTRIBUTE, e)

        return ModelAndView("/rest/error")
    }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy