mirror of
https://github.com/danieldemus/openhab-core.git
synced 2026-07-29 12:34:22 +02:00
[oauth] Fix exception wrapping (#4150)
Signed-off-by: Jacob Laursen <jacob-github@vindvejr.dk>
This commit is contained in:
+7
-5
@@ -327,11 +327,17 @@ public class OAuthConnector {
|
||||
|
||||
if (statusCode == HttpStatus.OK_200) {
|
||||
AccessTokenResponse jsonResponse = gson.fromJson(content, AccessTokenResponse.class);
|
||||
if (jsonResponse == null) {
|
||||
throw new OAuthException("Empty response content when deserializing AccessTokenResponse");
|
||||
}
|
||||
jsonResponse.setCreatedOn(Instant.now()); // this is not supplied by the response
|
||||
logger.debug("grant type {} to URL {} success", grantType, request.getURI());
|
||||
return jsonResponse;
|
||||
} else if (statusCode == HttpStatus.BAD_REQUEST_400) {
|
||||
OAuthResponseException errorResponse = gson.fromJson(content, OAuthResponseException.class);
|
||||
if (errorResponse == null) {
|
||||
throw new OAuthException("Empty response content when deserializing OAuthResponseException");
|
||||
}
|
||||
logger.error("grant type {} to URL {} failed with error code {}, description {}", grantType,
|
||||
request.getURI(), errorResponse.getError(), errorResponse.getErrorDescription());
|
||||
|
||||
@@ -345,12 +351,8 @@ public class OAuthConnector {
|
||||
throw new IOException("Exception in oauth communication, grant type " + grantType, e);
|
||||
} catch (JsonSyntaxException e) {
|
||||
throw new OAuthException(String.format(
|
||||
"Unable to deserialize json into AccessTokenResponse/ OAuthResponseException. httpCode: %d json: %s: %s",
|
||||
"Unable to deserialize json into AccessTokenResponse/OAuthResponseException. httpCode: %d json: %s: %s",
|
||||
statusCode, content, e.getMessage()), e);
|
||||
} catch (Exception e) {
|
||||
// Dont know what exception it is, wrap it up and throw it out
|
||||
throw new OAuthException(
|
||||
"Exception in oauth communication, grant type " + grantType + ": " + e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user