В слой exceptions добавлен GeneralExceptionsHanler.java - класс отвечающий за обработку исключений и их корректое предсавление

This commit is contained in:
Daniil Makeev 2025-02-19 10:17:21 +03:00
parent a495e6a37e
commit e086567a26
4 changed files with 45 additions and 0 deletions

View File

@ -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;
}

View File

@ -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());
}
}

View File

@ -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;

View File

@ -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> {
}