Skip to content
Snippets Groups Projects
Commit 7e0d59d3 authored by Neelesh Thakur's avatar Neelesh Thakur
Browse files

fix global exception API response

parent 93d04002
No related branches found
No related tags found
1 merge request!384fix global exception API response
Pipeline #182839 failed
......@@ -76,7 +76,7 @@ public class GlobalErrorController implements ErrorController {
err = exception == null ? "An unknown error has occurred" : exception.getMessage();
}
return String.format("{\"code\": %s, \"reason:\": \"%s\" \"message\":\"%s\" }",
return String.format("{\"code\": %s, \"reason\": \"%s\", \"message\":\"%s\"}",
statusCode, HttpStatus.resolve(statusCode).getReasonPhrase(), err);
}
......
......@@ -47,35 +47,35 @@ public class GlobalErrorControllerTest {
public void handleErrorGetTest() {
when(httpServletRequest.getAttribute(eq("javax.servlet.error.status_code"))).thenReturn(500);
String expected = globalErrorController.handleErrorGet(httpServletRequest);
assertEquals(expected, "{\"code\": 500, \"reason:\": \"Internal Server Error\" \"message\":\"An unknown error has occurred\" }");
assertEquals(expected, "{\"code\": 500, \"reason\": \"Internal Server Error\", \"message\":\"An unknown error has occurred\"}");
}
@Test
public void handleErrorPutTest() {
when(httpServletRequest.getAttribute(eq("javax.servlet.error.status_code"))).thenReturn(404);
String expected = globalErrorController.handleErrorPut(httpServletRequest);
assertEquals(expected, "{\"code\": 404, \"reason:\": \"Not Found\" \"message\":\"sample exception\" }");
assertEquals(expected, "{\"code\": 404, \"reason\": \"Not Found\", \"message\":\"sample exception\"}");
}
@Test
public void handleErrorPatchTest() {
when(httpServletRequest.getAttribute(eq("javax.servlet.error.status_code"))).thenReturn(500);
String expected = globalErrorController.handleErrorPatch(httpServletRequest);
assertEquals(expected, "{\"code\": 500, \"reason:\": \"Internal Server Error\" \"message\":\"An unknown error has occurred\" }");
assertEquals(expected, "{\"code\": 500, \"reason\": \"Internal Server Error\", \"message\":\"An unknown error has occurred\"}");
}
@Test
public void handleErrorDeleteTest() {
when(httpServletRequest.getAttribute(eq("javax.servlet.error.status_code"))).thenReturn(500);
String expected = globalErrorController.handleErrorDelete(httpServletRequest);
assertEquals(expected, "{\"code\": 500, \"reason:\": \"Internal Server Error\" \"message\":\"An unknown error has occurred\" }");
assertEquals(expected, "{\"code\": 500, \"reason\": \"Internal Server Error\", \"message\":\"An unknown error has occurred\"}");
}
@Test
public void handleErrorPostTest() {
when(httpServletRequest.getAttribute(eq("javax.servlet.error.status_code"))).thenReturn(500);
String expected = globalErrorController.handleErrorPost(httpServletRequest);
assertEquals(expected, "{\"code\": 500, \"reason:\": \"Internal Server Error\" \"message\":\"An unknown error has occurred\" }");
assertEquals(expected, "{\"code\": 500, \"reason\": \"Internal Server Error\", \"message\":\"An unknown error has occurred\"}");
}
@Test
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment