Hello World SME Invoker Service
[nonrtric.git] / sample-services / hello-world-sme-invoker / src / main / java / org / oransc / nonrtric / sample / exception / GlobalExceptionHandler.java
diff --git a/sample-services/hello-world-sme-invoker/src/main/java/org/oransc/nonrtric/sample/exception/GlobalExceptionHandler.java b/sample-services/hello-world-sme-invoker/src/main/java/org/oransc/nonrtric/sample/exception/GlobalExceptionHandler.java
new file mode 100644 (file)
index 0000000..414adf0
--- /dev/null
@@ -0,0 +1,39 @@
+/*-\r
+ * ========================LICENSE_START=================================\r
+ * O-RAN-SC\r
+ * %%\r
+ * Copyright (C) 2024 OpenInfra Foundation Europe.\r
+ * %%\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ *\r
+ *      http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ * ========================LICENSE_END===================================\r
+ */\r
+\r
+package org.oransc.nonrtric.sample.exception;\r
+\r
+import org.springframework.http.HttpStatus;\r
+import org.springframework.http.MediaType;\r
+import org.springframework.http.ResponseEntity;\r
+import org.springframework.web.bind.annotation.ControllerAdvice;\r
+import org.springframework.web.bind.annotation.ExceptionHandler;\r
+\r
+@ControllerAdvice\r
+public class GlobalExceptionHandler {\r
+\r
+    @ExceptionHandler(CapifAccessException.class)\r
+    public ResponseEntity<String> handleCapifAccessException(CapifAccessException ex) {\r
+        return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR)\r
+            .contentType(MediaType.TEXT_PLAIN)\r
+            .body(ex.getMessage());\r
+    }\r
+}\r
+\r