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

org.springdoc.sample1.ExceptionTranslator Maven / Gradle / Ivy

There is a newer version: 3.1.2
Show newest version
package org.springdoc.sample1;

import java.util.UUID;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseStatus;

@ControllerAdvice
public class ExceptionTranslator {

	private static final Logger LOGGER = LoggerFactory.getLogger(ExceptionTranslator.class);

	@ExceptionHandler({ Exception.class })
	@ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)
	public ResponseEntity handleRunTimeException(RuntimeException e) {
		return error(HttpStatus.INTERNAL_SERVER_ERROR, e);
    }


	private ResponseEntity error(HttpStatus status, Exception e) {
		LOGGER.error("Exception : ", e);
		return ResponseEntity.status(status).body(new ErrorMessage(UUID.randomUUID().toString(), e.getMessage()));
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy