Adding exception templates

This commit is contained in:
Niktia 2025-02-19 12:49:49 +03:00
parent 9ff70c9279
commit 2fe6907b94
14 changed files with 168 additions and 0 deletions

View File

@ -0,0 +1,7 @@
package com.example.nto.exception;
public class AuthorityNotFoundException extends RuntimeException {
public AuthorityNotFoundException(String message) {
super(message);
}
}

View File

@ -0,0 +1,7 @@
package com.example.nto.exception;
public class EmailAlreadyExistsException extends RuntimeException {
public EmailAlreadyExistsException(String message) {
super(message);
}
}

View File

@ -0,0 +1,7 @@
package com.example.nto.exception;
public class EntersNotFoundException extends RuntimeException {
public EntersNotFoundException(String message) {
super(message);
}
}

View File

@ -0,0 +1,7 @@
package com.example.nto.exception;
public class InvalidBirthDateException extends RuntimeException {
public InvalidBirthDateException(String message) {
super(message);
}
}

View File

@ -0,0 +1,7 @@
package com.example.nto.exception;
public class InvalidDescriptionException extends RuntimeException {
public InvalidDescriptionException(String message) {
super(message);
}
}

View File

@ -0,0 +1,7 @@
package com.example.nto.exception;
public class InvalidNameException extends RuntimeException {
public InvalidNameException(String message) {
super(message);
}
}

View File

@ -0,0 +1,7 @@
package com.example.nto.exception;
public class InvalidPasswordException extends RuntimeException {
public InvalidPasswordException(String message) {
super(message);
}
}

View File

@ -0,0 +1,7 @@
package com.example.nto.exception;
public class NoRequestBodyException extends RuntimeException {
public NoRequestBodyException(String message) {
super(message);
}
}

View File

@ -0,0 +1,7 @@
package com.example.nto.exception;
public class NoRequestParamsException extends RuntimeException {
public NoRequestParamsException(String message) {
super(message);
}
}

View File

@ -0,0 +1,7 @@
package com.example.nto.exception;
public class OtherException extends RuntimeException {
public OtherException(String message) {
super(message);
}
}

View File

@ -0,0 +1,7 @@
package com.example.nto.exception;
public class UserHasNoCenterException extends RuntimeException {
public UserHasNoCenterException(String message) {
super(message);
}
}

View File

@ -0,0 +1,7 @@
package com.example.nto.exception;
public class UserNotFoundException extends RuntimeException {
public UserNotFoundException(String message) {
super(message);
}
}

View File

@ -0,0 +1,7 @@
package com.example.nto.exception;
public class UsernameAlreadyExistsException extends RuntimeException {
public UsernameAlreadyExistsException(String message) {
super(message);
}
}

View File

@ -0,0 +1,77 @@
package com.example.nto.exception.handler;
import com.example.nto.exception.*;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
@ControllerAdvice
public class GlobalExceptionHandler {
@ExceptionHandler(EntersNotFoundException.class)
public ResponseEntity<String> handleEntersNotFoundException(EntersNotFoundException e) {
return new ResponseEntity<>(e.getMessage(), HttpStatus.NOT_FOUND);
}
@ExceptionHandler(UserNotFoundException.class)
public ResponseEntity<String> handleUserNotFoundException(UserNotFoundException e) {
return new ResponseEntity<>(e.getMessage(), HttpStatus.NOT_FOUND);
}
@ExceptionHandler(UserHasNoCenterException.class)
public ResponseEntity<String> handleUserException(UserHasNoCenterException e) {
return new ResponseEntity<>(e.getMessage(), HttpStatus.CONFLICT);
}
@ExceptionHandler(NoRequestBodyException.class)
public ResponseEntity<String> handleNoRequestBodyException(NoRequestBodyException e) {
return new ResponseEntity<>(e.getMessage(), HttpStatus.BAD_REQUEST);
}
@ExceptionHandler(EmailAlreadyExistsException.class)
public ResponseEntity<String> handleEmailAlreadyExistsException(EmailAlreadyExistsException e) {
return new ResponseEntity<>(e.getMessage(), HttpStatus.CONFLICT);
}
@ExceptionHandler(NoRequestParamsException.class)
public ResponseEntity<String> handleNoRequestParamsException(NoRequestParamsException e) {
return new ResponseEntity<>(e.getMessage(), HttpStatus.BAD_REQUEST);
}
@ExceptionHandler(InvalidBirthDateException.class)
public ResponseEntity<String> handleInvalidBirthDateException(InvalidBirthDateException e) {
return new ResponseEntity<>(e.getMessage(), HttpStatus.BAD_REQUEST);
}
@ExceptionHandler(InvalidPasswordException.class)
public ResponseEntity<String> handleInvalidPasswordException(InvalidPasswordException e) {
return new ResponseEntity<>(e.getMessage(), HttpStatus.BAD_REQUEST);
}
@ExceptionHandler(InvalidNameException.class)
public ResponseEntity<String> handleInvalidNameException(InvalidNameException e) {
return new ResponseEntity<>(e.getMessage(), HttpStatus.BAD_REQUEST);
}
@ExceptionHandler(InvalidDescriptionException.class)
public ResponseEntity<String> handleInvalidDescriptionException(InvalidDescriptionException e) {
return new ResponseEntity<>(e.getMessage(), HttpStatus.BAD_REQUEST);
}
@ExceptionHandler(OtherException.class)
public ResponseEntity<String> handleOtherException(OtherException e) {
return new ResponseEntity<>(e.getMessage(), HttpStatus.INTERNAL_SERVER_ERROR);
}
@ExceptionHandler(UsernameAlreadyExistsException.class)
public ResponseEntity<String> handleUsernameAlreadyExistsException(UsernameAlreadyExistsException e) {
return new ResponseEntity<>(e.getMessage(), HttpStatus.CONFLICT);
}
@ExceptionHandler(AuthorityNotFoundException.class)
public ResponseEntity<String> handleAuthorityNotFoundException(AuthorityNotFoundException e) {
return new ResponseEntity<>(e.getMessage(), HttpStatus.NOT_FOUND);
}
}