/* * Copyright (c) 2023. yo-saito. All Rights Reserved. */ package net.piedpiper.bremer import net.piedpiper.bremer.exception.BadRequestException import net.piedpiper.bremer.exception.NotFoundException import org.springframework.http.HttpStatus import org.springframework.http.ResponseEntity import org.springframework.web.bind.annotation.ControllerAdvice import org.springframework.web.bind.annotation.ExceptionHandler @ControllerAdvice class ExceptionControllerAdvice { class ErrorMessageModel( val status: Int, val message: String? ) @ExceptionHandler fun handleNotFoundException(e: BadRequestException): ResponseEntity<ErrorMessageModel> { return ResponseEntity( ErrorMessageModel( HttpStatus.BAD_REQUEST.value(), e.message ), HttpStatus.BAD_REQUEST ) } @ExceptionHandler fun handleBadRequestException(e: NotFoundException): ResponseEntity<ErrorMessageModel> { return ResponseEntity( ErrorMessageModel( HttpStatus.NOT_FOUND.value(), e.message ), HttpStatus.NOT_FOUND ) } }