summaryrefslogtreecommitdiffstats
path: root/src/main/java/org/onap/dcae/restapi/ApiException.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/org/onap/dcae/restapi/ApiException.java')
-rw-r--r--src/main/java/org/onap/dcae/restapi/ApiException.java26
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() {