Skip to content

Package: ThrowableInfo

ThrowableInfo

nameinstructionbranchcomplexitylinemethod
ThrowableInfo()
M: 9 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 4 C: 0
0%
M: 1 C: 0
0%
ThrowableInfo(Response.Status, Throwable)
M: 34 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 10 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%

Coverage

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