1 |
48617
|
claudio.at
|
package eu.dnetlib.openaire.exporter;
|
2 |
|
|
|
3 |
49994
|
claudio.at
|
import com.fasterxml.jackson.annotation.JsonAutoDetect;
|
4 |
48617
|
claudio.at
|
import org.apache.commons.lang3.StringUtils;
|
5 |
|
|
import org.apache.commons.lang3.exception.ExceptionUtils;
|
6 |
|
|
import org.apache.commons.logging.Log;
|
7 |
|
|
import org.apache.commons.logging.LogFactory;
|
8 |
|
|
import org.springframework.http.HttpStatus;
|
9 |
|
|
import org.springframework.web.bind.annotation.ExceptionHandler;
|
10 |
|
|
import org.springframework.web.bind.annotation.ResponseBody;
|
11 |
|
|
import org.springframework.web.bind.annotation.ResponseStatus;
|
12 |
|
|
|
13 |
|
|
/**
|
14 |
|
|
* Created by claudio on 18/07/2017.
|
15 |
|
|
*/
|
16 |
|
|
public abstract class AbstractExporterController {
|
17 |
|
|
|
18 |
|
|
private static final Log log = LogFactory.getLog(AbstractExporterController.class); // NOPMD by marko on 11/24/08 5:02 PM
|
19 |
|
|
|
20 |
|
|
@ResponseBody
|
21 |
|
|
@ExceptionHandler({Exception.class, Throwable.class})
|
22 |
|
|
@ResponseStatus(value = HttpStatus.INTERNAL_SERVER_ERROR)
|
23 |
|
|
public ErrorMessage handleSqlException(final Exception e) {
|
24 |
|
|
log.debug(e.getMessage(), e);
|
25 |
|
|
if (StringUtils.containsIgnoreCase(ExceptionUtils.getRootCauseMessage(e), "Broken pipe")) {
|
26 |
|
|
return null; //socket is closed, cannot return any response
|
27 |
|
|
} else {
|
28 |
|
|
return new ErrorMessage(e);
|
29 |
|
|
}
|
30 |
|
|
}
|
31 |
|
|
|
32 |
49994
|
claudio.at
|
@JsonAutoDetect
|
33 |
48617
|
claudio.at
|
public class ErrorMessage {
|
34 |
|
|
|
35 |
|
|
private final String message;
|
36 |
|
|
private final String stacktrace;
|
37 |
|
|
|
38 |
|
|
public ErrorMessage(final Exception e) {
|
39 |
|
|
this(e.getMessage(), ExceptionUtils.getStackTrace(e));
|
40 |
|
|
}
|
41 |
|
|
|
42 |
|
|
public ErrorMessage(final String message, final String stacktrace) {
|
43 |
|
|
this.message = message;
|
44 |
|
|
this.stacktrace = stacktrace;
|
45 |
|
|
}
|
46 |
|
|
|
47 |
|
|
public String getMessage() {
|
48 |
|
|
return this.message;
|
49 |
|
|
}
|
50 |
|
|
|
51 |
|
|
public String getStacktrace() {
|
52 |
|
|
return this.stacktrace;
|
53 |
|
|
}
|
54 |
|
|
}
|
55 |
|
|
|
56 |
|
|
}
|