]> source.dussan.org Git - jgit.git/commitdiff
FileLfsServlet: Return HTTP 422 instead of 400 60/77760/4
authorDavid Pursehouse <david.pursehouse@gmail.com>
Fri, 22 Jul 2016 08:21:20 +0000 (17:21 +0900)
committerDavid Pursehouse <david.pursehouse@gmail.com>
Wed, 27 Jul 2016 02:01:14 +0000 (11:01 +0900)
According to the specification [1], the error response status code
should be 422 when there is a validation error with one or more of
the objects in the request

[1] https://github.com/github/git-lfs/blob/master/docs/api/v1/http-v1-batch.md#response-errors

Change-Id: Id03fe00a2109b896d9a154228a14a33bce5accc3
Signed-off-by: David Pursehouse <david.pursehouse@gmail.com>
org.eclipse.jgit.lfs.server.test/tst/org/eclipse/jgit/lfs/server/fs/DownloadTest.java
org.eclipse.jgit.lfs.server/src/org/eclipse/jgit/lfs/server/fs/FileLfsServlet.java

index 6c4f3cbb99834842cb67047cb1d86ba79b062529..ac707eacf05b797e705ef5aef5545f2260a702eb 100644 (file)
@@ -78,7 +78,7 @@ public class DownloadTest extends LfsServerTest {
                        getContent(id.name().substring(0, 60), f);
                        fail("expected RuntimeException");
                } catch (RuntimeException e) {
-                       assertEquals("Status: 400 Bad Request",
+                       assertEquals("Status: 422 Unprocessable Entity",
                                        e.getMessage());
                }
        }
@@ -93,7 +93,7 @@ public class DownloadTest extends LfsServerTest {
                        getContent(id.name().replace('f', 'z'), f);
                        fail("expected RuntimeException");
                } catch (RuntimeException e) {
-                       assertEquals("Status: 400 Bad Request",
+                       assertEquals("Status: 422 Unprocessable Entity",
                                        e.getMessage());
                }
        }
index 586941357a672c237b34276801099f1e88502ac2..925dea8de52959028eda68375b712818faf8eac6 100644 (file)
@@ -121,14 +121,14 @@ public class FileLfsServlet extends HttpServlet {
                        HttpServletResponse rsp) throws IOException {
                String info = req.getPathInfo();
                if (info.length() != 1 + Constants.LONG_OBJECT_ID_STRING_LENGTH) {
-                       sendError(rsp, HttpStatus.SC_BAD_REQUEST, MessageFormat
+                       sendError(rsp, HttpStatus.SC_UNPROCESSABLE_ENTITY, MessageFormat
                                        .format(LfsServerText.get().invalidPathInfo, info));
                        return null;
                }
                try {
                        return LongObjectId.fromString(info.substring(1, 65));
                } catch (InvalidLongObjectIdException e) {
-                       sendError(rsp, HttpStatus.SC_BAD_REQUEST, e.getMessage());
+                       sendError(rsp, HttpStatus.SC_UNPROCESSABLE_ENTITY, e.getMessage());
                        return null;
                }
        }