Skip to content

Commit

Permalink
FIX (#16)
Browse files Browse the repository at this point in the history
* Test: 테스트용 application.yml 파일 추가

* Feat: Dockerfile 작성

* Refactor: AI 요구사항에 맞게 코드 수정

* Fix: H2 관련 설정 삭제

* Refactor: 식당 ID를 반환하도록 추가

* Refactor: AI 요구사항에 맞춰 수정

* Refactor: AI 요구사항에 맞도록 수정

* Test: 테스트 코드 수정

* Refactor: 회원 상세정보 필드 추가

* Refactor: 테스트 환경 간 모든 요청 허용

* Feat: 에러 발생 시 CORS 설정 추가

* Refactor: 회원 상세 정보 입력 로직 수정
  • Loading branch information
pjh5365 authored Nov 19, 2024
1 parent 065b9a7 commit 61cd09f
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,9 @@ public static MemberDetail toEntity(Member member, MemberDetailRequest request)
.age(request.getAge())
.location(request.getLocation())
.mainPreference(request.getMainPreference())
.subExperience(request.getSubExperience())
.subPreference(request.getSubPreference())
.mainExperience(request.getMainExperience())
.subExperience(request.getSubExperience())
.physicalStatus(request.getPhysicalStatus())
.build();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

import jakarta.servlet.http.HttpServletResponse;
import lombok.extern.slf4j.Slf4j;

/**
Expand All @@ -18,15 +19,24 @@
@RestControllerAdvice
public class ControllerAdvice {

private void addCorsHeaders(HttpServletResponse response) {
response.setHeader("Access-Control-Allow-Origin", "*");
response.setHeader("Access-Control-Allow-Methods", "GET, POST, PUT, DELETE, OPTIONS");
response.setHeader("Access-Control-Allow-Headers", "Authorization, Content-Type");
response.setHeader("Access-Control-Allow-Credentials", "true");
}

@ExceptionHandler(Exception.class)
public ResponseEntity<ApiResponse<String>> common(Exception e) {
public ResponseEntity<ApiResponse<String>> common(Exception e, HttpServletResponse response) {
addCorsHeaders(response); // CORS 헤더 추가
log.error("[밥상일터]: 예상치 못한 예외가 발생하였습니다. 예외내용 = {}", e.getMessage());
return ResponseEntity.status(HttpStatus.BAD_REQUEST)
.body(ApiResponse.failure("관리자에게 문의해주세요."));
}

@ExceptionHandler({IllegalArgumentException.class, AccessDeniedException.class})
public ResponseEntity<ApiResponse<String>> illegalArgument(Exception e) {
public ResponseEntity<ApiResponse<String>> illegalArgument(Exception e, HttpServletResponse response) {
addCorsHeaders(response); // CORS 헤더 추가
return ResponseEntity.status(HttpStatus.BAD_REQUEST)
.body(ApiResponse.failure(e.getMessage()));
}
Expand Down

0 comments on commit 61cd09f

Please sign in to comment.