Improve diagnostics for 403 response to upgrade issue creation

See gh-30304
This commit is contained in:
Andy Wilkinson 2022-05-16 11:26:10 +01:00
parent 5ce39254de
commit ac65d35f75
1 changed files with 12 additions and 2 deletions

View File

@ -23,6 +23,8 @@ import java.util.function.Function;
import java.util.stream.Collectors;
import org.springframework.http.ResponseEntity;
import org.springframework.web.client.HttpClientErrorException.Forbidden;
import org.springframework.web.client.RestClientException;
import org.springframework.web.client.RestTemplate;
/**
@ -56,8 +58,16 @@ final class StandardGitHubRepository implements GitHubRepository {
catch (InterruptedException ex) {
Thread.currentThread().interrupt();
}
ResponseEntity<Map> response = this.rest.postForEntity("issues", requestBody, Map.class);
return (Integer) response.getBody().get("number");
try {
ResponseEntity<Map> response = this.rest.postForEntity("issues", requestBody, Map.class);
return (Integer) response.getBody().get("number");
}
catch (RestClientException ex) {
if (ex instanceof Forbidden) {
System.out.println("Received 403 response with headers " + ((Forbidden) ex).getResponseHeaders());
}
throw ex;
}
}
@Override