Skip to content

Commit

Permalink
Merge pull request #41 from catenax-ng/2.0.8
Browse files Browse the repository at this point in the history
[chore|v2.0.9 ] api.yaml update in docs
  • Loading branch information
almadigabor authored Aug 17, 2023
2 parents 1bd26e2 + c4141d5 commit 3eac752
Show file tree
Hide file tree
Showing 3 changed files with 373 additions and 142 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@
import org.springframework.web.context.request.WebRequest;
import org.springframework.web.servlet.mvc.method.annotation.ResponseEntityExceptionHandler;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.JsonMappingException;
import com.fasterxml.jackson.databind.ObjectMapper;

import feign.FeignException;
import jakarta.validation.ConstraintViolationException;
import lombok.extern.slf4j.Slf4j;

Expand Down Expand Up @@ -65,6 +70,29 @@ public ResponseEntity<Map<String, String>> handleValidationException(ValidationE
return new ResponseEntity<>(errorResponse, HttpStatus.BAD_REQUEST);
}

@ExceptionHandler(FeignException.class)
public ResponseEntity<Map<String, String>> handleFeignException(FeignException ex, WebRequest request) {
log.error("FeignException: " + ex.getMessage());
log.error("FeignException RequestBody: " + ex.request());
log.error("FeignException ResponseBody: " + ex.contentUTF8());
ObjectMapper objmap = new ObjectMapper();
Map<String, String> errorResponse = new HashMap<>();
errorResponse.put("msg", "Error in remote service execution");
try {
@SuppressWarnings("unchecked")
Map<String, Object> map = objmap.readValue(ex.contentUTF8(), Map.class);
Object object = map.get("errors");
if (object != null)
errorResponse = prepareErrorResponse(object.toString());
} catch (JsonMappingException e) {
log.error("FeignException JsonMappingException " + e.getMessage());
} catch (JsonProcessingException e) {
log.error("FeignException JsonProcessingException " + e.getMessage());
}

return new ResponseEntity<>(errorResponse, HttpStatus.BAD_REQUEST);
}

@ExceptionHandler(ConstraintViolationException.class)
public ResponseEntity<Map<String, String>> handleConstraintValidationException(ConstraintViolationException ex,
WebRequest request) {
Expand Down
Loading

0 comments on commit 3eac752

Please sign in to comment.