X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=blobdiff_plain;f=webapp-backend%2Fsrc%2Fmain%2Fjava%2Forg%2Foransc%2Fric%2Fportal%2Fdashboard%2Fmodel%2FErrorTransport.java;h=2a90fca52b423bdfbbc066130297fa8dab32ed14;hb=a0180adc6a1e1ec09472549596428b70d48db3fc;hp=035b9efb98272eee0015b42d4173f7b9d4be006c;hpb=be7a01eda7e4fb9f97a18009d727e6a0692e9399;p=portal%2Fric-dashboard.git diff --git a/webapp-backend/src/main/java/org/oransc/ric/portal/dashboard/model/ErrorTransport.java b/webapp-backend/src/main/java/org/oransc/ric/portal/dashboard/model/ErrorTransport.java index 035b9efb..2a90fca5 100644 --- a/webapp-backend/src/main/java/org/oransc/ric/portal/dashboard/model/ErrorTransport.java +++ b/webapp-backend/src/main/java/org/oransc/ric/portal/dashboard/model/ErrorTransport.java @@ -2,7 +2,7 @@ * ========================LICENSE_START================================= * O-RAN-SC * %% - * Copyright (C) 2019 AT&T Intellectual Property and Nokia + * Copyright (C) 2019 AT&T Intellectual Property * %% * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -20,14 +20,19 @@ package org.oransc.ric.portal.dashboard.model; +import java.time.Instant; + /** - * Model for message returned on failure, to be serialized as JSON. + * This mimics the model Spring-Boot uses for a message returned on failure, to + * be serialized as JSON. */ public class ErrorTransport implements IDashboardResponse { + private Instant timestamp; private Integer status; private String error; - private String exception; + private String message; + private String path; /** * Builds an empty object. @@ -37,38 +42,52 @@ public class ErrorTransport implements IDashboardResponse { } /** - * Builds an object with the specified values. + * Convenience constructor for minimal value set. + * + * @param status + * Integer value like 400 + * @param error + * Error message + */ + public ErrorTransport(int status, String error) { + this(status, error, null, null); + } + + /** + * Convenience constructor for populating an error from an exception * - * @param statusCode - * Integer value like 400 - * @param errMsg - * Explanation + * @param status + * Integer value like 400 + * @param throwable + * The caught exception/throwable to convert to String with + * an upper bound on characters */ - public ErrorTransport(int statusCode, String errMsg) { - this(statusCode, errMsg, null); + public ErrorTransport(int status, Throwable throwable) { + this.timestamp = Instant.now(); + this.status = status; + final int enough = 256; + String exString = throwable.toString(); + this.error = exString.length() > enough ? exString.substring(0, enough) : exString; } /** - * Builds an object with the specified status code, message and a String version - * of the exception. + * Builds an object with all fields * - * @param statusCode - * Integer value like 500 - * @param errMsg - * Explanation - * @param exception - * Exception that should be reported; optional and ignored - * if null. + * @param status + * Integer value like 500 + * @param error + * Explanation + * @param message + * Additional explanation + * @param path + * Requested path */ - public ErrorTransport(int statusCode, String errMsg, Exception exception) { - this.status = statusCode; - this.error = errMsg; - if (exception != null) { - final int enough = 512; - String exString = exception.toString(); - String exceptionMsg = exString.length() > enough ? exString.substring(0, enough) : exString; - this.exception = exceptionMsg; - } + public ErrorTransport(int status, String error, String message, String path) { + this.timestamp = Instant.now(); + this.status = status; + this.error = error; + this.message = message; + this.path = path; } public Integer getStatus() { @@ -79,6 +98,22 @@ public class ErrorTransport implements IDashboardResponse { this.status = status; } + public String getMessage() { + return message; + } + + public void setMessage(String error) { + this.message = error; + } + + public Instant getTimestamp() { + return timestamp; + } + + public void setTimestamp(Instant timestamp) { + this.timestamp = timestamp; + } + public String getError() { return error; } @@ -87,12 +122,18 @@ public class ErrorTransport implements IDashboardResponse { this.error = error; } - public String getException() { - return exception; + public String getPath() { + return path; + } + + public void setPath(String path) { + this.path = path; } - public void setException(String exception) { - this.exception = exception; + @Override + public String toString() { + return this.getClass().getSimpleName() + "[timestamp=" + getTimestamp() + ", error=" + getError() + ", path=" + + getPath() + "]"; } }