Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(exception): segregate event manager exceptions #130

Merged
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
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package evrentan.community.eventmanager.exception;
package evrentan.community.eventmanager.dto.exception;


import lombok.Builder;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package evrentan.community.eventmanager.exception;

public class EventAlreadyExistsException extends RuntimeException {

private final String message;

public EventAlreadyExistsException(String message) {
this.message = message;
}

@Override
public String getMessage(){
return message;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package evrentan.community.eventmanager.exception;

public class EventNotFoundException extends RuntimeException {

private final String message;

public EventNotFoundException(String message) {
this.message = message;
}

@Override
public String getMessage(){
return message;
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package evrentan.community.eventmanager.exception;


import evrentan.community.eventmanager.dto.exception.CustomRestError;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.ws.rs.BadRequestException;
import jakarta.ws.rs.InternalServerErrorException;
Expand Down Expand Up @@ -29,7 +30,10 @@ public class GlobalRestExceptionHandler {
* @author <a href="https://github.com/Onuraktasj">Onur Aktas</a>
* @since 1.0.0
*/
@ExceptionHandler(BadRequestException.class)
@ExceptionHandler({
BadRequestException.class,
IdNotMatchException.class
})
public ResponseEntity<CustomRestError> badRequestException(final Exception exception, final HttpServletRequest httpServletRequest){
var customRestError = CustomRestError.builder()
.message(exception.getCause().getMessage())
Expand All @@ -50,7 +54,10 @@ public ResponseEntity<CustomRestError> badRequestException(final Exception excep
* @author <a href="https://github.com/Onuraktasj">Onur Aktas</a>
* @since 1.0.0
*/
@ExceptionHandler(NotFoundException.class)
@ExceptionHandler({
NotFoundException.class,
EventNotFoundException.class
})
public ResponseEntity<CustomRestError> notFoundException(final Exception exception, final HttpServletRequest httpServletRequest){
var customRestError = CustomRestError.builder()
.message(exception.getCause().getMessage())
Expand Down Expand Up @@ -79,6 +86,17 @@ public ResponseEntity<CustomRestError> notFoundException(final Exception excepti
return responseEntity(customRestError);
}

@ExceptionHandler(EventAlreadyExistsException.class)
public ResponseEntity<CustomRestError> alreadyExistsException(final Exception exception, final HttpServletRequest httpServletRequest){
var customRestError = CustomRestError.builder()
.message(exception.getCause().getMessage())
.status(HttpStatus.CONFLICT.value())
.build();
return responseEntity(customRestError);
}



private static ResponseEntity<CustomRestError> responseEntity(CustomRestError customRestError){
return ResponseEntity.status(HttpStatus.valueOf(customRestError.getStatus()))
.body(customRestError);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package evrentan.community.eventmanager.exception;

public class IdNotMatchException extends RuntimeException {

private final String message;

public IdNotMatchException(String message){
this.message = message;
}

@Override
public String getMessage(){
return message;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package evrentan.community.eventmanager.message;

public class ExceptionMessage {

public static final String EVENT_NOT_FOUND = "User does not exist !!!";
public static final String EVENT_ALREADY_EXISTS = "User already exists !!!";
public static final String ID_NOT_MATCH = "Id does not match !!!";
}
Loading