42 lines
1.0 KiB
Plaintext
42 lines
1.0 KiB
Plaintext
package eu.dnetlib.lbs.controllers;
|
|
|
|
import org.apache.commons.lang3.exception.ExceptionUtils;
|
|
import org.springframework.http.HttpStatus;
|
|
import org.springframework.web.bind.annotation.ExceptionHandler;
|
|
import org.springframework.web.bind.annotation.ResponseBody;
|
|
import org.springframework.web.bind.annotation.ResponseStatus;
|
|
|
|
public abstract class AbstractLbsController {
|
|
|
|
@ExceptionHandler(Exception.class)
|
|
@ResponseStatus(value = HttpStatus.INTERNAL_SERVER_ERROR)
|
|
public @ResponseBody ErrorMessage handleException(final Exception e) {
|
|
return new ErrorMessage(e);
|
|
}
|
|
|
|
public class ErrorMessage {
|
|
|
|
private final String message;
|
|
private final String stacktrace;
|
|
|
|
public ErrorMessage(final Exception e) {
|
|
this(e.getMessage(), ExceptionUtils.getStackTrace(e));
|
|
}
|
|
|
|
public ErrorMessage(final String message, final String stacktrace) {
|
|
this.message = message;
|
|
this.stacktrace = stacktrace;
|
|
}
|
|
|
|
public String getMessage() {
|
|
return this.message;
|
|
}
|
|
|
|
public String getStacktrace() {
|
|
return this.stacktrace;
|
|
}
|
|
|
|
}
|
|
|
|
}
|