Skip to content

Commit

Permalink
fix: microsoft replies "accessDenied" in body(JSON)
Browse files Browse the repository at this point in the history
  • Loading branch information
jzacsh committed Jan 23, 2025
1 parent 3eae329 commit a47e34e
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ public MicrosoftApiResponse returnConvertDtpException(String message)

private FatalState toFatalState() {
checkState(isFatal(), "cannot explain fatal state when is apparently recoverable");
if (httpStatus() == 403 && httpMessage().contains("Access Denied")) {
if (httpStatus() == 403 && bodyContains("accessDenied")) {
return FatalState.FATAL_STATE_FATAL_PERMISSION_DENIED;
}
// Nit: we _could_ just parse the body into json properly and make sure the JSON body "message"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,16 @@ public void testOkay() throws IOException {

@Test
public void testErrorPermission() throws IOException {
Response networkResponse = fakeResponse(403, "Access Denied").build();
Response networkResponse = fakeResponse(403, "",
"{" +
"\"error\": {" +
"\"code\":\"accessDenied\"," +
"\"message\":\"Access Denied\"," +
"\"localizedMessage\":\"アイテムが削除されているか、期限切れになっているか、またはこのアイテムへのアクセス許可がない可能性があります。詳細については、このアイテムの所有者に問い合わせてください。\"," +
"\"innerError\": {\"date\":\"2024-12-24T01:03:02\",\"request-id\":\"fake-request-id\",\"client-request-id\":\"fake-client-request-id\"}" +
"}" +
"}"
).build();

MicrosoftApiResponse response = MicrosoftApiResponse.ofResponse(networkResponse);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,16 @@ public void testImportItemPermissionDenied() throws Exception {
r.url()
.toString()
.equals("https://www.baseurl.com/v1.0/me/drive/special/photos/children")));
Response response = fakeErrorResponse(403, "Access Denied", "{\"id\": \"id1\"}").build();
Response response = fakeResponse(403, "",
"{" +
"\"error\": {" +
"\"code\":\"accessDenied\"," +
"\"message\":\"Access Denied\"," +
"\"localizedMessage\":\"アイテムが削除されているか、期限切れになっているか、またはこのアイテムへのアクセス許可がない可能性があります。詳細については、このアイテムの所有者に問い合わせてください。\"," +
"\"innerError\": {\"date\":\"2024-12-24T01:03:02\",\"request-id\":\"fake-request-id\",\"client-request-id\":\"fake-client-request-id\"}" +
"}" +
"}"
).build();
when(call.execute()).thenReturn(response);

assertThrows(
Expand Down

0 comments on commit a47e34e

Please sign in to comment.