X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=blobdiff_plain;f=sample-services%2Fhello-world-sme-invoker%2Fsrc%2Fmain%2Fjava%2Forg%2Foransc%2Fnonrtric%2Fsample%2Fexception%2FGlobalExceptionHandler.java;fp=sample-services%2Fhello-world-sme-invoker%2Fsrc%2Fmain%2Fjava%2Forg%2Foransc%2Fnonrtric%2Fsample%2Fexception%2FGlobalExceptionHandler.java;h=414adf050e288300a9d439cd77295a225a61748e;hb=dafdbe531634823882261f2ce8c9cf334b579b52;hp=0000000000000000000000000000000000000000;hpb=53ebb953e0e18e695fd0e807c2f1282ef54ceeee;p=nonrtric.git 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 index 00000000..414adf05 --- /dev/null +++ b/sample-services/hello-world-sme-invoker/src/main/java/org/oransc/nonrtric/sample/exception/GlobalExceptionHandler.java @@ -0,0 +1,39 @@ +/*- + * ========================LICENSE_START================================= + * O-RAN-SC + * %% + * Copyright (C) 2024 OpenInfra Foundation Europe. + * %% + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ========================LICENSE_END=================================== + */ + +package org.oransc.nonrtric.sample.exception; + +import org.springframework.http.HttpStatus; +import org.springframework.http.MediaType; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.ControllerAdvice; +import org.springframework.web.bind.annotation.ExceptionHandler; + +@ControllerAdvice +public class GlobalExceptionHandler { + + @ExceptionHandler(CapifAccessException.class) + public ResponseEntity handleCapifAccessException(CapifAccessException ex) { + return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR) + .contentType(MediaType.TEXT_PLAIN) + .body(ex.getMessage()); + } +} +