diff --git a/org.review_board.ereviewboard.core/src/org/review_board/ereviewboard/core/client/ErrorCode.java b/org.review_board.ereviewboard.core/src/org/review_board/ereviewboard/core/client/ErrorCode.java index 156cd4e..f1f7115 100644 --- a/org.review_board.ereviewboard.core/src/org/review_board/ereviewboard/core/client/ErrorCode.java +++ b/org.review_board.ereviewboard.core/src/org/review_board/ereviewboard/core/client/ErrorCode.java @@ -7,7 +7,7 @@ */ public enum ErrorCode { - OBJECT_DOES_NOT_EXIST(100), INVALID_FORM_DATA(105); + OBJECT_DOES_NOT_EXIST(100), INVALID_FORM_DATA(105), FILE_NOT_FOUND(207); private final int _errorCode; diff --git a/org.review_board.ereviewboard.core/src/org/review_board/ereviewboard/core/client/RestfulReviewboardReader.java b/org.review_board.ereviewboard.core/src/org/review_board/ereviewboard/core/client/RestfulReviewboardReader.java index 003616a..9e564ae 100644 --- a/org.review_board.ereviewboard.core/src/org/review_board/ereviewboard/core/client/RestfulReviewboardReader.java +++ b/org.review_board.ereviewboard.core/src/org/review_board/ereviewboard/core/client/RestfulReviewboardReader.java @@ -46,6 +46,7 @@ import org.review_board.ereviewboard.core.ReviewboardCorePlugin; import org.review_board.ereviewboard.core.exception.ReviewboardApiException; import org.review_board.ereviewboard.core.exception.ReviewboardException; +import org.review_board.ereviewboard.core.exception.ReviewboardFileNotFoundException; import org.review_board.ereviewboard.core.exception.ReviewboardInvalidFormDataException; import org.review_board.ereviewboard.core.exception.ReviewboardObjectDoesNotExistException; import org.review_board.ereviewboard.core.model.*; @@ -107,6 +108,9 @@ private JSONObject checkedGetJSonRootObject(String source) throws ReviewboardExc throw new ReviewboardInvalidFormDataException(gatherFieldErrors(object)); else if ( ErrorCode.OBJECT_DOES_NOT_EXIST.is(code) ) throw new ReviewboardObjectDoesNotExistException(message); + else if (ErrorCode.FILE_NOT_FOUND.is(code)) + throw new ReviewboardFileNotFoundException(object.getString("file"), + object.getString("revision")); throw new ReviewboardApiException(message, code); } diff --git a/org.review_board.ereviewboard.core/src/org/review_board/ereviewboard/core/exception/ReviewboardFileNotFoundException.java b/org.review_board.ereviewboard.core/src/org/review_board/ereviewboard/core/exception/ReviewboardFileNotFoundException.java new file mode 100644 index 0000000..7903739 --- /dev/null +++ b/org.review_board.ereviewboard.core/src/org/review_board/ereviewboard/core/exception/ReviewboardFileNotFoundException.java @@ -0,0 +1,21 @@ +package org.review_board.ereviewboard.core.exception; + +import org.review_board.ereviewboard.core.client.ErrorCode; + +/** + * The ReviewboardFileNotFoundException signals that a file that was + * referenced in an API call was not found + * + */ +public class ReviewboardFileNotFoundException extends ReviewboardApiException { + + public ReviewboardFileNotFoundException() { + + } + + public ReviewboardFileNotFoundException(String fileName, String revision) { + super("No file named '" + fileName + "' found in the repository at revision '" + revision + + "'", ErrorCode.FILE_NOT_FOUND.getErrorCode()); + } + +} diff --git a/org.review_board.ereviewboard.tests/src/org/review_board/ereviewboard/core/client/RestfulReviewboardReaderTest.java b/org.review_board.ereviewboard.tests/src/org/review_board/ereviewboard/core/client/RestfulReviewboardReaderTest.java index 8780719..844afe9 100644 --- a/org.review_board.ereviewboard.tests/src/org/review_board/ereviewboard/core/client/RestfulReviewboardReaderTest.java +++ b/org.review_board.ereviewboard.tests/src/org/review_board/ereviewboard/core/client/RestfulReviewboardReaderTest.java @@ -44,7 +44,6 @@ import static org.junit.Assert.assertThat; import static org.junit.Assert.assertTrue; - import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; @@ -59,6 +58,7 @@ import org.junit.Test; import org.review_board.ereviewboard.core.ReviewboardAttributeMapper; import org.review_board.ereviewboard.core.exception.ReviewboardException; +import org.review_board.ereviewboard.core.exception.ReviewboardFileNotFoundException; import org.review_board.ereviewboard.core.exception.ReviewboardInvalidFormDataException; import org.review_board.ereviewboard.core.model.*; import org.review_board.ereviewboard.core.model.Change.Field; @@ -494,6 +494,18 @@ public void readInvalidFormDataException() throws ReviewboardException, IOExcept } } + @Test + public void readFileNotFoundException() throws IOException, ReviewboardException { + try { + reader.ensureSuccess(readJsonTestResource("file-not-found.json")); + } catch (ReviewboardFileNotFoundException e) { + assertThat( + e.getMessage(), + is("No file named '/simple-project/w/runtime-ereviewboard/simple-project/src/com/example/Logic.java' found in the repository at revision '1'")); + assertThat(ErrorCode.FILE_NOT_FOUND.is(e.getCode()), is(true)); + } + } + @Test public void readChange() throws ReviewboardException, IOException { diff --git a/org.review_board.ereviewboard.tests/testdata/jsondata/file-not-found.json b/org.review_board.ereviewboard.tests/testdata/jsondata/file-not-found.json new file mode 100644 index 0000000..729a1e6 --- /dev/null +++ b/org.review_board.ereviewboard.tests/testdata/jsondata/file-not-found.json @@ -0,0 +1 @@ +{"stat": "fail", "err": {"msg": "The file was not found in the repository", "code": 207}, "file": "/simple-project/w/runtime-ereviewboard/simple-project/src/com/example/Logic.java", "revision": "1"} \ No newline at end of file