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=c0157067339a4622df2c90f1a847de01e90cdb36;hb=425ca107bd805dda906b62fc2b03a6f3c815b8a1;hp=ff801bb2c706a70b4b57de8526763a23162531ee;hpb=f660cae7a447b60d84ef75f7c2bcbf62412d4579;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 ff801bb2..c0157067 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 @@ -1,6 +1,6 @@ /*- * ========================LICENSE_START================================= - * ORAN-OSC + * O-RAN-SC * %% * Copyright (C) 2019 AT&T Intellectual Property and Nokia * %% @@ -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 statusCode - * Integer value like 400 - * @param errMsg - * Explanation + * @param status + * Integer value like 400 + * @param error + * Error message */ - public ErrorTransport(int statusCode, String errMsg) { - this(statusCode, errMsg, null); + public ErrorTransport(int status, String error) { + this(status, error, null, null); } /** - * Builds an object with the specified status code, message and a String version - * of the exception. + * Convenience constructor for populating an error from an exception * - * @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 400 + * @param throwable + * The caught exception/throwable to convert to String with + * an upper bound on characters */ - 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, 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 all fields + * + * @param status + * Integer value like 500 + * @param error + * Explanation + * @param message + * Additional explanation + * @param path + * Requested path + */ + 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,12 @@ public class ErrorTransport implements IDashboardResponse { this.error = error; } - public String getException() { - return exception; + public String getPath() { + return path; } - public void setException(String exception) { - this.exception = exception; + public void setPath(String path) { + this.path = path; } }