Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/main/java/com/spotify/github/v3/clients/GitHubClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -741,10 +741,10 @@ private RequestNotOkException mapException(final Response res, final Request req
String bodyString = res.body() != null ? res.body().string() : "";
if (res.code() == FORBIDDEN) {
if (bodyString.contains("Repository was archived so is read-only")) {
return new ReadOnlyRepositoryException(request.url().encodedPath(), res.code(), bodyString);
return new ReadOnlyRepositoryException(request.method(), request.url().encodedPath(), res.code(), bodyString);
}
}
return new RequestNotOkException(request.url().encodedPath(), res.code(), bodyString);
return new RequestNotOkException(request.method(), request.url().encodedPath(), res.code(), bodyString);
}

CompletableFuture<Response> processPossibleRedirects(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*
* http://www.apache.org/licenses/LICENSE-2.0
*
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*
* http://www.apache.org/licenses/LICENSE-2.0
*
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
Expand All @@ -25,11 +25,13 @@ public class ReadOnlyRepositoryException extends RequestNotOkException {
/**
* Instantiates a new Read only repository exception.
*
* @param method HTTP method
* @param path the path
* @param statusCode the status code
* @param msg the msg
*/
public ReadOnlyRepositoryException(final String path, final int statusCode, final String msg) {
super(path, statusCode, msg);
public ReadOnlyRepositoryException(
final String method, final String path, final int statusCode, final String msg) {
super(method, path, statusCode, msg);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*
* http://www.apache.org/licenses/LICENSE-2.0
*
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
Expand Down Expand Up @@ -38,23 +38,28 @@
public class RequestNotOkException extends GithubException {

private final int statusCode;
private final String method;
private final String path;
private final String msg;

private static String decoratedMessage(final String path, final int statusCode, final String msg) {
return String.format("%s %d: %s", path, statusCode, msg);
private static String decoratedMessage(
final String method, final String path, final int statusCode, final String msg) {
return String.format("%s %s %d: %s", method, path, statusCode, msg);
}

/**
* Response to request came back with non-2xx status code
*
* @param method HTTP method
* @param path URI path
* @param statusCode status of repsonse
* @param msg response body
*/
public RequestNotOkException(final String path, final int statusCode, final String msg) {
super(decoratedMessage(path, statusCode, msg));
public RequestNotOkException(
final String method, final String path, final int statusCode, final String msg) {
super(decoratedMessage(method, path, statusCode, msg));
this.statusCode = statusCode;
this.method = method;
this.path = path;
this.msg = msg;
}
Expand All @@ -77,6 +82,15 @@ public int statusCode() {
return statusCode;
}

/**
* Get request HTTP method
*
* @return method
*/
public String method() {
return method;
}

/**
* Get request URI path
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public void succeed() {
@Test
public void fail() {
final Span span = new OpenCensusSpan(wrapped);
span.failure(new RequestNotOkException("path", 404, "Not found"));
span.failure(new RequestNotOkException("method", "path", 404, "Not found"));
span.close();

verify(wrapped).setStatus(Status.UNKNOWN);
Expand All @@ -57,7 +57,7 @@ public void fail() {
@Test
public void failOnServerError() {
final Span span = new OpenCensusSpan(wrapped);
span.failure(new RequestNotOkException("path", 500, "Internal Server Error"));
span.failure(new RequestNotOkException("method", "path", 500, "Internal Server Error"));
span.close();

verify(wrapped).setStatus(Status.UNKNOWN);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,10 @@ public void testRequestNotOkException() throws Throwable {
assertThat(e.getCause() instanceof RequestNotOkException, is(true));
RequestNotOkException e1 = (RequestNotOkException) e.getCause();
assertThat(e1.statusCode(), is(409));
assertThat(e1.method(), is("POST"));
assertThat(e1.path(), is("/repos/testorg/testrepo/merges"));
assertThat(e1.getMessage(), containsString("POST"));
assertThat(e1.getMessage(), containsString("/repos/testorg/testrepo/merges"));
assertThat(e1.getMessage(), containsString("Merge Conflict"));
assertThat(e1.getRawMessage(), containsString("Merge Conflict"));
}
Expand Down