Skip to content

Commit cd4a37c

Browse files
Renamed ApiError to ErrorResponse
1 parent 7987006 commit cd4a37c

File tree

2 files changed

+12
-12
lines changed

2 files changed

+12
-12
lines changed

src/main/java/net/javadiscord/javabot/api/exception/ApiError.java renamed to src/main/java/net/javadiscord/javabot/api/exception/ErrorResponse.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,4 @@
1010
* @param message The errors' message.
1111
* @param errors An array of additional error notices.
1212
*/
13-
public record ApiError(HttpStatus status, String message, String... errors) {}
13+
public record ErrorResponse(HttpStatus status, String message, String... errors) {}

src/main/java/net/javadiscord/javabot/api/exception/RestExceptionHandler.java

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,11 @@ public class RestExceptionHandler extends ResponseEntityExceptionHandler {
2020
* Handles all {@link MethodArgumentTypeMismatchException}s.
2121
*
2222
* @param e The {@link MethodArgumentTypeMismatchException} which was thrown.
23-
* @return The {@link ResponseEntity} containing the {@link ApiError}.
23+
* @return The {@link ResponseEntity} containing the {@link ErrorResponse}.
2424
*/
25-
@ExceptionHandler({ MethodArgumentTypeMismatchException.class })
26-
public ResponseEntity<ApiError> handleMethodArgumentTypeMismatch(@NotNull MethodArgumentTypeMismatchException e) {
27-
ApiError error = new ApiError(HttpStatus.BAD_REQUEST, e.getLocalizedMessage(),
25+
@ExceptionHandler(MethodArgumentTypeMismatchException.class)
26+
public ResponseEntity<ErrorResponse> handleMethodArgumentTypeMismatch(@NotNull MethodArgumentTypeMismatchException e) {
27+
ErrorResponse error = new ErrorResponse(HttpStatus.BAD_REQUEST, e.getLocalizedMessage(),
2828
String.format("%s should be of type %s", e.getName(), e.getRequiredType() != null ? e.getRequiredType().getName() : ""));
2929
return new ResponseEntity<>(error, error.status());
3030
}
@@ -33,23 +33,23 @@ public ResponseEntity<ApiError> handleMethodArgumentTypeMismatch(@NotNull Method
3333
* Handles all {@link InvalidEntityIdException}s.
3434
*
3535
* @param e The {@link InvalidEntityIdException} which was thrown.
36-
* @return The {@link ResponseEntity} containing the {@link ApiError}.
36+
* @return The {@link ResponseEntity} containing the {@link ErrorResponse}.
3737
*/
38-
@ExceptionHandler({ InvalidEntityIdException.class })
39-
public ResponseEntity<ApiError> handleInvalidEntityIdException(@NotNull InvalidEntityIdException e) {
40-
ApiError error = new ApiError(HttpStatus.BAD_REQUEST, e.getLocalizedMessage(), "Entity should be of type: " + e.getRequiredEntity().getName());
38+
@ExceptionHandler(InvalidEntityIdException.class)
39+
public ResponseEntity<ErrorResponse> handleInvalidEntityIdException(@NotNull InvalidEntityIdException e) {
40+
ErrorResponse error = new ErrorResponse(HttpStatus.BAD_REQUEST, e.getLocalizedMessage(), "Entity should be of type: " + e.getRequiredEntity().getName());
4141
return new ResponseEntity<>(error, error.status());
4242
}
4343

4444
/**
4545
* Handles all {@link SQLException}s.
4646
*
4747
* @param e The {@link SQLException} which was thrown.
48-
* @return The {@link ResponseEntity} containing the {@link ApiError}.
48+
* @return The {@link ResponseEntity} containing the {@link ErrorResponse}.
4949
*/
5050
@ExceptionHandler({ InternalServerException.class })
51-
public ResponseEntity<ApiError> handleInternalServerException(@NotNull InternalServerException e) {
52-
ApiError error = new ApiError(HttpStatus.BAD_REQUEST, e.getCause().getLocalizedMessage(), e.getLocalizedMessage());
51+
public ResponseEntity<ErrorResponse> handleInternalServerException(@NotNull InternalServerException e) {
52+
ErrorResponse error = new ErrorResponse(HttpStatus.BAD_REQUEST, e.getCause().getLocalizedMessage(), e.getLocalizedMessage());
5353
return new ResponseEntity<>(error, error.status());
5454
}
5555
}

0 commit comments

Comments
 (0)