Skip to content

Package: ThrowableInfo

ThrowableInfo

nameinstructionbranchcomplexitylinemethod
ThrowableInfo()
M: 3 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
ThrowableInfo(Response.Status, Throwable)
M: 29 C: 0
0%
M: 4 C: 0
0%
M: 3 C: 0
0%
M: 9 C: 0
0%
M: 1 C: 0
0%
getHttpErrorCode()
M: 3 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
getMessage()
M: 3 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
getStackTrace()
M: 3 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
setHttpErrorCode(Response.Status)
M: 5 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
setMessage(String)
M: 4 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
setStackTrace(String)
M: 4 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
static {...}
M: 6 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%

Coverage

1: /*******************************************************************************
2: * Copyright (c) 2017, 2022 Eurotech and/or its affiliates and others
3: *
4: * This program and the accompanying materials are made
5: * available under the terms of the Eclipse Public License 2.0
6: * which is available at https://www.eclipse.org/legal/epl-2.0/
7: *
8: * SPDX-License-Identifier: EPL-2.0
9: *
10: * Contributors:
11: * Eurotech - initial API and implementation
12: *******************************************************************************/
13: package org.eclipse.kapua.app.api.core.exception.model;
14:
15: import java.io.PrintWriter;
16: import java.io.StringWriter;
17: import javax.ws.rs.core.Response.Status;
18: import javax.xml.bind.annotation.XmlAccessType;
19: import javax.xml.bind.annotation.XmlAccessorType;
20: import javax.xml.bind.annotation.XmlElement;
21: import javax.xml.bind.annotation.XmlRootElement;
22:
23: import org.eclipse.kapua.app.api.core.settings.KapuaApiCoreSetting;
24: import org.eclipse.kapua.app.api.core.settings.KapuaApiCoreSettingKeys;
25:
26: @XmlRootElement(name = "throwableInfo")
27: @XmlAccessorType(XmlAccessType.FIELD)
28: public class ThrowableInfo {
29:
30: private static final boolean SHOW_STACKTRACE = KapuaApiCoreSetting.getInstance().getBoolean(KapuaApiCoreSettingKeys.API_EXCEPTION_STACKTRACE_SHOW, false);
31:
32: @XmlElement(name = "httpErrorCode")
33: private int httpErrorCode;
34:
35: @XmlElement(name = "message")
36: private String message;
37:
38: @XmlElement(name = "stackTrace")
39: private String stackTrace;
40:
41: protected ThrowableInfo() {
42: super();
43: }
44:
45: public ThrowableInfo(Status httpStatus, Throwable throwable) {
46: this.httpErrorCode = httpStatus.getStatusCode();
47:• if (throwable != null) {
48: this.message = throwable.getMessage();
49: // Print stack trace
50:• if (SHOW_STACKTRACE) {
51: StringWriter stringWriter = new StringWriter();
52: throwable.printStackTrace(new PrintWriter(stringWriter));
53: setStackTrace(stringWriter.toString());
54: }
55: }
56: }
57:
58: public int getHttpErrorCode() {
59: return httpErrorCode;
60: }
61:
62: public void setHttpErrorCode(Status httpErrorCode) {
63: this.httpErrorCode = httpErrorCode.getStatusCode();
64: }
65:
66: public String getMessage() {
67: return message;
68: }
69:
70: public void setMessage(String message) {
71: this.message = message;
72: }
73:
74: public String getStackTrace() {
75: return stackTrace;
76: }
77:
78: private void setStackTrace(String stackTrace) {
79: this.stackTrace = stackTrace;
80: }
81:
82: }