В слой exceptions добавлен GeneralExceptionsHanler.java - класс отвечающий за обработку исключений и их корректое предсавление
This commit is contained in:
parent
a495e6a37e
commit
e086567a26
@ -0,0 +1,13 @@
|
||||
package com.example.onomatopoeiaback.exceptions;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
@AllArgsConstructor
|
||||
@Getter
|
||||
@Setter
|
||||
public class ExceptionDTO {
|
||||
private String status;
|
||||
private String message;
|
||||
}
|
@ -0,0 +1,24 @@
|
||||
package com.example.onomatopoeiaback.exceptions;
|
||||
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.web.bind.annotation.ControllerAdvice;
|
||||
import org.springframework.web.bind.annotation.ExceptionHandler;
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
import org.springframework.web.bind.annotation.ResponseStatus;
|
||||
|
||||
@ControllerAdvice
|
||||
public class GeneralExceptionsHandler {
|
||||
@ResponseStatus(HttpStatus.BAD_REQUEST)
|
||||
@ExceptionHandler(BadRequestException.class)
|
||||
@ResponseBody
|
||||
public ExceptionDTO handleBadRequestException(BadRequestException e) {
|
||||
return new ExceptionDTO("BAD_REQUEST", e.getMessage());
|
||||
}
|
||||
|
||||
@ResponseStatus(HttpStatus.UNAUTHORIZED)
|
||||
@ExceptionHandler(UnauthorizedException.class)
|
||||
@ResponseBody
|
||||
public ExceptionDTO handleUnauthorizedException(UnauthorizedException e) {
|
||||
return new ExceptionDTO("UNAUTHORIZED", e.getMessage());
|
||||
}
|
||||
}
|
@ -1,5 +1,6 @@
|
||||
package com.example.onomatopoeiaback.repository;
|
||||
|
||||
import com.example.onomatopoeiaback.domain.employee.Employee;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
|
@ -0,0 +1,7 @@
|
||||
package com.example.onomatopoeiaback.repository;
|
||||
|
||||
import com.example.onomatopoeiaback.domain.qrcode.QrCode;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
|
||||
public interface QrCodeRepository extends JpaRepository<QrCode, Long> {
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user