-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'develop' into feature/otel-config
- Loading branch information
Showing
13 changed files
with
131 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
...ava/it/finanze/sanita/fse2/ms/gtw/dispatcher/client/RestTemplateResponseErrorHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package it.finanze.sanita.fse2.ms.gtw.dispatcher.client; | ||
|
||
|
||
import java.io.IOException; | ||
import java.nio.charset.StandardCharsets; | ||
|
||
import org.apache.commons.io.IOUtils; | ||
import org.springframework.http.HttpStatus; | ||
import org.springframework.http.client.ClientHttpResponse; | ||
import org.springframework.stereotype.Component; | ||
import org.springframework.web.client.ResponseErrorHandler; | ||
|
||
import com.google.gson.Gson; | ||
|
||
import it.finanze.sanita.fse2.ms.gtw.dispatcher.dto.response.ErrorResponseDTO; | ||
import it.finanze.sanita.fse2.ms.gtw.dispatcher.exceptions.BusinessException; | ||
import it.finanze.sanita.fse2.ms.gtw.dispatcher.exceptions.NoRecordFoundException; | ||
|
||
|
||
@Component | ||
public class RestTemplateResponseErrorHandler implements ResponseErrorHandler { | ||
|
||
@Override | ||
public boolean hasError(ClientHttpResponse httpResponse) throws IOException { | ||
return (httpResponse.getStatusCode().series() == HttpStatus.Series.CLIENT_ERROR || | ||
httpResponse.getStatusCode().series() == HttpStatus.Series.SERVER_ERROR); | ||
} | ||
|
||
@Override | ||
public void handleError(ClientHttpResponse httpResponse) throws IOException { | ||
String result = IOUtils.toString(httpResponse.getBody(), StandardCharsets.UTF_8); | ||
ErrorResponseDTO error = new Gson().fromJson(result, ErrorResponseDTO.class); | ||
if (httpResponse.getStatusCode() == HttpStatus.INTERNAL_SERVER_ERROR) { | ||
throw new BusinessException(error); | ||
} else if(httpResponse.getStatusCode() == HttpStatus.NOT_FOUND){ | ||
throw new NoRecordFoundException(error); | ||
} else { | ||
throw new BusinessException("Generic error"); | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.