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] 예외 중앙처리 #11

Merged
merged 5 commits into from
Sep 24, 2024
Merged
Show file tree
Hide file tree
Changes from 4 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
@@ -0,0 +1,4 @@
package com.example.book_your_seat.common.constants;

public final class Constants {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.example.book_your_seat.common.entity;

import lombok.Data;

@Data
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@DaTa 어노테이션은 삭제해도 될 것 같아요! getter가 필요해도 setter는 생성하지 않는게 좋다고 생각합니다!!

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

생성자에서 데이터를 입력받은 후 수정이나 조회가 필요 없어서 @DaTa 는 없어도 될 것 같습니당

public class ErrorResult {

private String code;

private String message;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

final 적용해도 될 것 같습니당


public ErrorResult(String code, String message) {
this.code = code;
this.message = message;
}

public ErrorResult(String code) {
this.code = code;
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
public ErrorResult(String code) {
this.code = code;
}
public ErrorResult(String code) {
this.code = code;
this.message = "bad request";
}

이렇게 수정하시면 record 사용가능 할 듯 합니다!

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package com.example.book_your_seat.common.exhandler;

import com.example.book_your_seat.common.entity.ErrorResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@Slf4j
@RestControllerAdvice
public class ExControllerAdvice {

@ExceptionHandler(IllegalArgumentException.class)
public ResponseEntity<ErrorResult> catchError(IllegalArgumentException e) {
log.error("[exceptionHandle] ex", e);

ErrorResult errorResult = new ErrorResult("BAD", e.getMessage());
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

이 부분의 "BAD"를 HttpStatus.BAD_REQUEST.name() 으로 바꾸시면 될 것 같습니다!

return new ResponseEntity<>(errorResult, HttpStatus.BAD_REQUEST);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public class Concert extends BaseEntity {
@OneToMany(mappedBy = "concert", cascade = CascadeType.ALL)
private final List<LikeConcert> likeConcerts = new ArrayList<>();

@OneToMany(mappedBy = "user", cascade = CascadeType.ALL)
@OneToMany(mappedBy = "concert", cascade = CascadeType.ALL)
private final List<Review> reviews = new ArrayList<>();

@OneToMany(mappedBy = "concert", cascade = CascadeType.ALL)
Expand Down
Loading