diff options
author | 2022-01-19 17:43:21 +0530 | |
---|---|---|
committer | 2022-02-25 08:59:10 +0530 | |
commit | a72ce419bce29ba8cf421eb74afad730d7cf374b (patch) | |
tree | 8ea71656ed6a6dfb7d1e5d01243c7b9ddb036bb4 /src/main/java/org/onap/dcae/restapi/ApiException.java | |
parent | bc40a9d58fe7ede6a41863b60466c776b388bbb3 (diff) |
RESTConf - Switch CBS client library to 1.8.7 or higher
Issue-ID: DCAEGEN2-2857
Signed-off-by: Mukesh Paliwal <mukesh.paliwal1@huawei.com>
Change-Id: I3242a29e2e09fae65dd1738b6883970ce436bf2a
Diffstat (limited to 'src/main/java/org/onap/dcae/restapi/ApiException.java')
-rw-r--r-- | src/main/java/org/onap/dcae/restapi/ApiException.java | 26 |
1 files changed, 23 insertions, 3 deletions
diff --git a/src/main/java/org/onap/dcae/restapi/ApiException.java b/src/main/java/org/onap/dcae/restapi/ApiException.java index d8c21b1..426ff87 100644 --- a/src/main/java/org/onap/dcae/restapi/ApiException.java +++ b/src/main/java/org/onap/dcae/restapi/ApiException.java @@ -3,7 +3,7 @@ * org.onap.dcaegen2.restconfcollector * ================================================================================ * Copyright (C) 2018 Nokia. All rights reserved. - * Copyright (C) 2018-2019 Huawei. All rights reserved. + * Copyright (C) 2018-2022 Huawei. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -23,21 +23,38 @@ package org.onap.dcae.restapi; import com.google.common.base.CaseFormat; import org.json.JSONObject; +import java.util.ArrayList; +import java.util.List; + /** * @author Pawel Szalapski (pawel.szalapski@nokia.com) */ public enum ApiException { - UNAUTHORIZED_USER(ExceptionType.POLICY_EXCEPTION, "POL2000", "Unauthorized user", 401); + + UNAUTHORIZED_USER(ExceptionType.POLICY_EXCEPTION, "POL2000", "Unauthorized user", 401), + NOT_FOUND(ExceptionType.SERVICE_EXCEPTION, "SVC2000", "The following service error occurred: %1. Error code is %2", List.of("Not Found","404"), 404), + REQUEST_TIMEOUT(ExceptionType.SERVICE_EXCEPTION, "SVC2000", "The following service error occurred: %1. Error code is %2", List.of("Request Timeout","408"), 408), + TOO_MANY_REQUESTS(ExceptionType.SERVICE_EXCEPTION, "SVC2000", "The following service error occurred: %1. Error code is %2", List.of("Too Many Requests","429"), 429), + INTERNAL_SERVER_ERROR(ExceptionType.SERVICE_EXCEPTION, "SVC2000", "The following service error occurred: %1. Error code is %2", List.of("Internal Server Error","500"), 500), + BAD_GATEWAY(ExceptionType.SERVICE_EXCEPTION, "SVC2000", "The following service error occurred: %1. Error code is %2", List.of("Bad Gateway","502"), 502), + SERVICE_UNAVAILABLE(ExceptionType.SERVICE_EXCEPTION, "SVC2000", "The following service error occurred: %1. Error code is %2", List.of("Service Unavailable","503"), 503), + GATEWAY_TIMEOUT(ExceptionType.SERVICE_EXCEPTION, "SVC2000", "The following service error occurred: %1. Error code is %2", List.of("Gateway Timeout","504"), 504); public final int httpStatusCode; private final ExceptionType type; private final String code; private final String details; + private final List<String> variables; ApiException(ExceptionType type, String code, String details, int httpStatusCode) { + this(type, code, details, new ArrayList<>(), httpStatusCode); + } + + ApiException(ExceptionType type, String code, String details, List<String> variables, int httpStatusCode) { this.type = type; this.code = code; this.details = details; + this.variables = variables; this.httpStatusCode = httpStatusCode; } @@ -45,6 +62,9 @@ public enum ApiException { JSONObject exceptionTypeNode = new JSONObject(); exceptionTypeNode.put("messageId", code); exceptionTypeNode.put("text", details); + if(!variables.isEmpty()) { + exceptionTypeNode.put("variables", variables); + } JSONObject requestErrorNode = new JSONObject(); requestErrorNode.put(type.toString(), exceptionTypeNode); @@ -55,7 +75,7 @@ public enum ApiException { } public enum ExceptionType { - POLICY_EXCEPTION; + SERVICE_EXCEPTION, POLICY_EXCEPTION; @Override public String toString() { |