2 * ========================LICENSE_START=================================
5 * Copyright (C) 2019 AT&T Intellectual Property
6 * Modifications Copyright (C) 2020 Nordix Foundation
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
19 * ========================LICENSE_END===================================
22 package org.oransc.portal.nonrtric.controlpanel.model;
24 import java.time.Instant;
27 * This mimics the model Spring-Boot uses for a message returned on failure, to
28 * be serialized as JSON.
30 public class ErrorTransport implements IControlpanelResponse {
32 private Instant timestamp;
33 private Integer status;
35 private String message;
39 * Builds an empty object.
41 public ErrorTransport() {
46 * Convenience constructor for minimal value set.
49 * Integer value like 400
53 public ErrorTransport(int status, String error) {
54 this(status, error, null, null);
58 * Convenience constructor for populating an error from an exception
61 * Integer value like 400
63 * The caught exception/throwable to convert to String with
64 * an upper bound on characters
66 public ErrorTransport(int status, Throwable throwable) {
67 this.timestamp = Instant.now();
69 final int enough = 256;
70 String exString = throwable.toString();
71 this.error = exString.length() > enough ? exString.substring(0, enough) : exString;
75 * Builds an object with all fields
78 * Integer value like 500
82 * Additional explanation
86 public ErrorTransport(int status, String error, String message, String path) {
87 this.timestamp = Instant.now();
90 this.message = message;
94 public Integer getStatus() {
98 public void setStatus(Integer status) {
102 public String getMessage() {
106 public void setMessage(String error) {
107 this.message = error;
110 public Instant getTimestamp() {
114 public void setTimestamp(Instant timestamp) {
115 this.timestamp = timestamp;
118 public String getError() {
122 public void setError(String error) {
126 public String getPath() {
130 public void setPath(String path) {