Skip to content

Commit

Permalink
Migrate to Spring 6
Browse files Browse the repository at this point in the history
  • Loading branch information
vkalapov committed Oct 4, 2024
1 parent 2af5f44 commit 92ab22f
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 13 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
<mockito.version>5.11.0</mockito.version>
<jackson.version>2.17.0</jackson.version>
<jackson.databind.version>2.17.0</jackson.databind.version>
<spring.version>5.3.34</spring.version>
<spring.version>6.1.10</spring.version>
<spring-security.version>5.8.11</spring-security.version>
<commons-io.version>2.16.1</commons-io.version>
<immutables.version>2.10.1</immutables.version>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,31 +1,30 @@
package com.sap.cloudfoundry.client.facade.rest;

import java.io.IOException;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.sap.cloudfoundry.client.facade.CloudOperationException;
import com.sap.cloudfoundry.client.facade.util.CloudUtil;
import org.springframework.http.HttpStatus;
import org.springframework.http.client.ClientHttpResponse;
import org.springframework.web.client.DefaultResponseErrorHandler;
import org.springframework.web.client.RestClientException;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.sap.cloudfoundry.client.facade.CloudOperationException;
import com.sap.cloudfoundry.client.facade.util.CloudUtil;
import java.io.IOException;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

public class CloudControllerResponseErrorHandler extends DefaultResponseErrorHandler {

private static CloudOperationException getException(ClientHttpResponse response) throws IOException {
HttpStatus statusCode = response.getStatusCode();
HttpStatus statusCode = HttpStatus.valueOf(response.getStatusCode()
.value());
String statusText = response.getStatusText();

ObjectMapper mapper = new ObjectMapper(); // can reuse, share globally

if (response.getBody() != null) {
try {
@SuppressWarnings("unchecked")
Map<String, Object> responseBody = mapper.readValue(response.getBody(), Map.class);
@SuppressWarnings("unchecked") Map<String, Object> responseBody = mapper.readValue(response.getBody(), Map.class);
String description = getTrimmedDescription(responseBody);
return new CloudOperationException(statusCode, statusText, description);
} catch (IOException e) {
Expand Down Expand Up @@ -63,7 +62,8 @@ private static String concatenateErrorMessages(List<Map<String, Object>> errors)

@Override
public void handleError(ClientHttpResponse response) throws IOException {
HttpStatus statusCode = response.getStatusCode();
HttpStatus statusCode = HttpStatus.valueOf(response.getStatusCode()
.value());
switch (statusCode.series()) {
case CLIENT_ERROR:
case SERVER_ERROR:
Expand Down

0 comments on commit 92ab22f

Please sign in to comment.