diff --git a/backend/src/main/java/com/mapbefine/mapbefine/atlas/exception/AtlasErrorCode.java b/backend/src/main/java/com/mapbefine/mapbefine/atlas/exception/AtlasErrorCode.java index bf6316de..a81f3d57 100644 --- a/backend/src/main/java/com/mapbefine/mapbefine/atlas/exception/AtlasErrorCode.java +++ b/backend/src/main/java/com/mapbefine/mapbefine/atlas/exception/AtlasErrorCode.java @@ -5,9 +5,9 @@ @Getter public enum AtlasErrorCode { - ILLEGAL_COORDINATE_RANGE("00000", "한국 내의 좌표만 입력해주세요."), - ILLEGAL_TOPIC_ID("00001", "유효하지 않은 지도입니다."), - ILLEGAL_MEMBER_ID("00002", "유효하지 않은 회원입니다."), + + ILLEGAL_TOPIC_ID("00000", "유효하지 않은 지도입니다."), + ILLEGAL_MEMBER_ID("00001", "유효하지 않은 회원입니다."), FORBIDDEN_TOPIC_ADD("00300", "모아보기 추가 권한이 없습니다."), FORBIDDEN_TOPIC_READ("00301", "지도 조회 권한이 없습니다."), ; diff --git a/backend/src/main/java/com/mapbefine/mapbefine/atlas/exception/AtlasException.java b/backend/src/main/java/com/mapbefine/mapbefine/atlas/exception/AtlasException.java index b07ce418..36159d7c 100644 --- a/backend/src/main/java/com/mapbefine/mapbefine/atlas/exception/AtlasException.java +++ b/backend/src/main/java/com/mapbefine/mapbefine/atlas/exception/AtlasException.java @@ -6,15 +6,15 @@ public class AtlasException { - public static class AtlasForbiddenException extends ForbiddenException { - public AtlasForbiddenException(AtlasErrorCode errorCode) { - super(new ErrorCode(errorCode.getCode(), errorCode.getMessage())); + public static class AtlasBadRequestException extends BadRequestException { + public AtlasBadRequestException(AtlasErrorCode errorCode) { + super(new ErrorCode<>(errorCode.getCode(), errorCode.getMessage())); } } - public static class AtlasBadRequestException extends BadRequestException { - public AtlasBadRequestException(AtlasErrorCode errorCode) { - super(new ErrorCode(errorCode.getCode(), errorCode.getMessage())); + public static class AtlasForbiddenException extends ForbiddenException { + public AtlasForbiddenException(AtlasErrorCode errorCode) { + super(new ErrorCode<>(errorCode.getCode(), errorCode.getMessage())); } } diff --git a/backend/src/main/java/com/mapbefine/mapbefine/auth/domain/member/User.java b/backend/src/main/java/com/mapbefine/mapbefine/auth/domain/member/User.java index 81612e75..d2444d49 100644 --- a/backend/src/main/java/com/mapbefine/mapbefine/auth/domain/member/User.java +++ b/backend/src/main/java/com/mapbefine/mapbefine/auth/domain/member/User.java @@ -51,7 +51,7 @@ private boolean isGroup(Long topicId) { } private boolean hasPermission(Long topicId) { - return topicsWithPermission.contains(topicId); + return createdTopic.contains(topicId) || topicsWithPermission.contains(topicId); } } diff --git a/backend/src/main/java/com/mapbefine/mapbefine/bookmark/application/BookmarkCommandService.java b/backend/src/main/java/com/mapbefine/mapbefine/bookmark/application/BookmarkCommandService.java index 4032537c..6f34de32 100644 --- a/backend/src/main/java/com/mapbefine/mapbefine/bookmark/application/BookmarkCommandService.java +++ b/backend/src/main/java/com/mapbefine/mapbefine/bookmark/application/BookmarkCommandService.java @@ -58,7 +58,7 @@ private Topic getTopicById(Long topicId) { private void validateBookmarkDuplication(AuthMember authMember, Long topicId) { if (isExistBookmark(authMember, topicId)) { - throw new BookmarkConflictException(CONFLICT_TOPIC_ALREADY_ADD); + throw new BookmarkConflictException(CONFLICT_TOPIC_ALREADY_ADD, topicId); } } diff --git a/backend/src/main/java/com/mapbefine/mapbefine/bookmark/exception/BookmarkException.java b/backend/src/main/java/com/mapbefine/mapbefine/bookmark/exception/BookmarkException.java index ab4dce63..9f751cd2 100644 --- a/backend/src/main/java/com/mapbefine/mapbefine/bookmark/exception/BookmarkException.java +++ b/backend/src/main/java/com/mapbefine/mapbefine/bookmark/exception/BookmarkException.java @@ -7,22 +7,21 @@ public class BookmarkException { - public static class BookmarkForbiddenException extends ForbiddenException { - public BookmarkForbiddenException(BookmarkErrorCode errorCode) { - super(new ErrorCode(errorCode.getCode(), errorCode.getMessage())); + public static class BookmarkBadRequestException extends BadRequestException { + public BookmarkBadRequestException(BookmarkErrorCode errorCode) { + super(new ErrorCode<>(errorCode.getCode(), errorCode.getMessage())); } } - public static class BookmarkBadRequestException extends BadRequestException { - public BookmarkBadRequestException(BookmarkErrorCode errorCode) { - super(new ErrorCode(errorCode.getCode(), errorCode.getMessage())); + public static class BookmarkForbiddenException extends ForbiddenException { + public BookmarkForbiddenException(BookmarkErrorCode errorCode) { + super(new ErrorCode<>(errorCode.getCode(), errorCode.getMessage())); } } public static class BookmarkConflictException extends ConflictException { - - public BookmarkConflictException(BookmarkErrorCode errorCode) { - super(new ErrorCode(errorCode.getCode(), errorCode.getMessage())); + public BookmarkConflictException(BookmarkErrorCode errorCode, Long id) { + super(new ErrorCode<>(errorCode.getCode(), errorCode.getMessage(), id)); } } diff --git a/backend/src/main/java/com/mapbefine/mapbefine/common/GlobalExceptionHandler.java b/backend/src/main/java/com/mapbefine/mapbefine/common/GlobalExceptionHandler.java index ce137b1a..a82843d9 100644 --- a/backend/src/main/java/com/mapbefine/mapbefine/common/GlobalExceptionHandler.java +++ b/backend/src/main/java/com/mapbefine/mapbefine/common/GlobalExceptionHandler.java @@ -2,8 +2,11 @@ import static org.springframework.http.HttpStatus.INTERNAL_SERVER_ERROR; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.ObjectMapper; import com.mapbefine.mapbefine.common.exception.ErrorCode; import com.mapbefine.mapbefine.common.exception.GlobalException; +import com.mapbefine.mapbefine.common.exception.dto.ErrorResponse; import jakarta.servlet.http.HttpServletRequest; import lombok.extern.slf4j.Slf4j; import org.springframework.http.ResponseEntity; @@ -14,19 +17,29 @@ @RestControllerAdvice public class GlobalExceptionHandler { + private final ObjectMapper objectMapper; + + public GlobalExceptionHandler(ObjectMapper objectMapper) { + this.objectMapper = objectMapper; + } + @ExceptionHandler(GlobalException.class) - public ResponseEntity handle(GlobalException exception, HttpServletRequest request) { + public ResponseEntity handle( + GlobalException exception, + HttpServletRequest request + ) throws JsonProcessingException { String exceptionSource = extractExceptionSource(exception); - ErrorCode errorCode = exception.getErrorCode(); + ErrorCode errorCode = exception.getErrorCode(); log.warn( - "source = {} \n {} = {} \n code = {} \n message = {}", + "source = {} \n {} = {} \n code = {} \n message = {} \n info = {}", exceptionSource, request.getMethod(), request.getRequestURI(), - errorCode.code(), errorCode.message() + errorCode.getCode(), errorCode.getMessage(), + objectMapper.writeValueAsString(errorCode.getInfo()) ); - return ResponseEntity.status(exception.getStatus()).body(errorCode); + return ResponseEntity.status(exception.getStatus()).body(ErrorResponse.from(errorCode)); } private String extractExceptionSource(Exception exception) { diff --git a/backend/src/main/java/com/mapbefine/mapbefine/common/exception/BadRequestException.java b/backend/src/main/java/com/mapbefine/mapbefine/common/exception/BadRequestException.java index f717df77..8f467576 100644 --- a/backend/src/main/java/com/mapbefine/mapbefine/common/exception/BadRequestException.java +++ b/backend/src/main/java/com/mapbefine/mapbefine/common/exception/BadRequestException.java @@ -4,13 +4,13 @@ public class BadRequestException extends GlobalException { - public BadRequestException(ErrorCode errorCode) { + public BadRequestException(ErrorCode errorCode) { super(errorCode, HttpStatus.BAD_REQUEST); } public static class ImageBadRequestException extends BadRequestException { public ImageBadRequestException() { - super(new ErrorCode("03000", "잘못된 형식의 URL입니다.")); + super(new ErrorCode<>("03000", "잘못된 형식의 URL입니다.")); } } diff --git a/backend/src/main/java/com/mapbefine/mapbefine/common/exception/ConflictException.java b/backend/src/main/java/com/mapbefine/mapbefine/common/exception/ConflictException.java index 368199ff..c329d500 100644 --- a/backend/src/main/java/com/mapbefine/mapbefine/common/exception/ConflictException.java +++ b/backend/src/main/java/com/mapbefine/mapbefine/common/exception/ConflictException.java @@ -4,7 +4,7 @@ public class ConflictException extends GlobalException { - public ConflictException(ErrorCode errorCode) { + public ConflictException(ErrorCode errorCode) { super(errorCode, HttpStatus.CONFLICT); } diff --git a/backend/src/main/java/com/mapbefine/mapbefine/common/exception/ErrorCode.java b/backend/src/main/java/com/mapbefine/mapbefine/common/exception/ErrorCode.java index 66d2a9a7..a0c2fde4 100644 --- a/backend/src/main/java/com/mapbefine/mapbefine/common/exception/ErrorCode.java +++ b/backend/src/main/java/com/mapbefine/mapbefine/common/exception/ErrorCode.java @@ -1,7 +1,25 @@ package com.mapbefine.mapbefine.common.exception; -public record ErrorCode( - String code, - String message -) { +import com.fasterxml.jackson.annotation.JsonInclude; +import lombok.Getter; + +@Getter +@JsonInclude(JsonInclude.Include.NON_NULL) +public class ErrorCode { + + private final String code; + private final String message; + private T info; + + public ErrorCode(String code, String message, T info) { + this.code = code; + this.message = message; + this.info = info; + } + + public ErrorCode(String code, String message) { + this.code = code; + this.message = message; + } + } diff --git a/backend/src/main/java/com/mapbefine/mapbefine/common/exception/ForbiddenException.java b/backend/src/main/java/com/mapbefine/mapbefine/common/exception/ForbiddenException.java index fdb31cbc..87de6352 100644 --- a/backend/src/main/java/com/mapbefine/mapbefine/common/exception/ForbiddenException.java +++ b/backend/src/main/java/com/mapbefine/mapbefine/common/exception/ForbiddenException.java @@ -4,7 +4,7 @@ public class ForbiddenException extends GlobalException { - public ForbiddenException(ErrorCode errorCode) { + public ForbiddenException(ErrorCode errorCode) { super(errorCode, HttpStatus.FORBIDDEN); } diff --git a/backend/src/main/java/com/mapbefine/mapbefine/common/exception/GlobalException.java b/backend/src/main/java/com/mapbefine/mapbefine/common/exception/GlobalException.java index 4c500f01..68a4c1ad 100644 --- a/backend/src/main/java/com/mapbefine/mapbefine/common/exception/GlobalException.java +++ b/backend/src/main/java/com/mapbefine/mapbefine/common/exception/GlobalException.java @@ -6,11 +6,11 @@ @Getter public class GlobalException extends RuntimeException { - private final ErrorCode errorCode; + private final ErrorCode errorCode; private final HttpStatus status; - public GlobalException(ErrorCode errorCode, HttpStatus status) { - super(errorCode.message()); + public GlobalException(ErrorCode errorCode, HttpStatus status) { + super(errorCode.getMessage()); this.errorCode = errorCode; this.status = status; } diff --git a/backend/src/main/java/com/mapbefine/mapbefine/common/exception/NotFoundException.java b/backend/src/main/java/com/mapbefine/mapbefine/common/exception/NotFoundException.java index 688c7cac..68c171c6 100644 --- a/backend/src/main/java/com/mapbefine/mapbefine/common/exception/NotFoundException.java +++ b/backend/src/main/java/com/mapbefine/mapbefine/common/exception/NotFoundException.java @@ -4,7 +4,7 @@ public class NotFoundException extends GlobalException { - public NotFoundException(ErrorCode errorCode) { + public NotFoundException(ErrorCode errorCode) { super(errorCode, HttpStatus.NOT_FOUND); } diff --git a/backend/src/main/java/com/mapbefine/mapbefine/common/exception/UnauthorizedException.java b/backend/src/main/java/com/mapbefine/mapbefine/common/exception/UnauthorizedException.java index 01f22082..ed952c8f 100644 --- a/backend/src/main/java/com/mapbefine/mapbefine/common/exception/UnauthorizedException.java +++ b/backend/src/main/java/com/mapbefine/mapbefine/common/exception/UnauthorizedException.java @@ -4,7 +4,7 @@ public class UnauthorizedException extends GlobalException { - public UnauthorizedException(ErrorCode errorCode) { + public UnauthorizedException(ErrorCode errorCode) { super(errorCode, HttpStatus.UNAUTHORIZED); } diff --git a/backend/src/main/java/com/mapbefine/mapbefine/common/exception/dto/ErrorResponse.java b/backend/src/main/java/com/mapbefine/mapbefine/common/exception/dto/ErrorResponse.java new file mode 100644 index 00000000..53b4530f --- /dev/null +++ b/backend/src/main/java/com/mapbefine/mapbefine/common/exception/dto/ErrorResponse.java @@ -0,0 +1,12 @@ +package com.mapbefine.mapbefine.common.exception.dto; + +import com.mapbefine.mapbefine.common.exception.ErrorCode; + +public record ErrorResponse( + String code, + String message +) { + public static ErrorResponse from(ErrorCode errorCode) { + return new ErrorResponse(errorCode.getCode(), errorCode.getMessage()); + } +} diff --git a/backend/src/main/java/com/mapbefine/mapbefine/location/exception/LocationException.java b/backend/src/main/java/com/mapbefine/mapbefine/location/exception/LocationException.java index 457f41b1..50284405 100644 --- a/backend/src/main/java/com/mapbefine/mapbefine/location/exception/LocationException.java +++ b/backend/src/main/java/com/mapbefine/mapbefine/location/exception/LocationException.java @@ -8,7 +8,7 @@ public class LocationException { public static class LocationBadRequestException extends BadRequestException { public LocationBadRequestException(LocationErrorCode errorCode) { - super(new ErrorCode(errorCode.getCode(), errorCode.getMessage())); + super(new ErrorCode<>(errorCode.getCode(), errorCode.getMessage())); } } diff --git a/backend/src/main/java/com/mapbefine/mapbefine/member/application/MemberQueryService.java b/backend/src/main/java/com/mapbefine/mapbefine/member/application/MemberQueryService.java index 646eaf92..c032cf36 100644 --- a/backend/src/main/java/com/mapbefine/mapbefine/member/application/MemberQueryService.java +++ b/backend/src/main/java/com/mapbefine/mapbefine/member/application/MemberQueryService.java @@ -34,7 +34,7 @@ public MemberDetailResponse findById(Long id) { private Member findMemberById(Long id) { return memberRepository.findById(id) - .orElseThrow(() -> new MemberNotFoundException(MemberErrorCode.MEMBER_NOT_FOUND)); + .orElseThrow(() -> new MemberNotFoundException(MemberErrorCode.MEMBER_NOT_FOUND, id)); } public List findAll() { diff --git a/backend/src/main/java/com/mapbefine/mapbefine/member/exception/MemberException.java b/backend/src/main/java/com/mapbefine/mapbefine/member/exception/MemberException.java index afd3e1e8..ec98e9d0 100644 --- a/backend/src/main/java/com/mapbefine/mapbefine/member/exception/MemberException.java +++ b/backend/src/main/java/com/mapbefine/mapbefine/member/exception/MemberException.java @@ -8,13 +8,13 @@ public class MemberException { public static class MemberBadRequestException extends BadRequestException { public MemberBadRequestException(MemberErrorCode errorCode) { - super(new ErrorCode(errorCode.getCode(), errorCode.getMessage())); + super(new ErrorCode<>(errorCode.getCode(), errorCode.getMessage())); } } public static class MemberNotFoundException extends NotFoundException { - public MemberNotFoundException(MemberErrorCode errorCode) { - super(new ErrorCode(errorCode.getCode(), errorCode.getMessage())); + public MemberNotFoundException(MemberErrorCode errorCode, Long id) { + super(new ErrorCode<>(errorCode.getCode(), errorCode.getMessage(), id)); } } diff --git a/backend/src/main/java/com/mapbefine/mapbefine/oauth/domain/AuthCodeRequestUrlProviderComposite.java b/backend/src/main/java/com/mapbefine/mapbefine/oauth/domain/AuthCodeRequestUrlProviderComposite.java index b1af7345..a2a3c518 100644 --- a/backend/src/main/java/com/mapbefine/mapbefine/oauth/domain/AuthCodeRequestUrlProviderComposite.java +++ b/backend/src/main/java/com/mapbefine/mapbefine/oauth/domain/AuthCodeRequestUrlProviderComposite.java @@ -29,7 +29,7 @@ public String provide(OauthServerType oauthServerType) { public AuthCodeRequestUrlProvider getProvider(OauthServerType oauthServerType) { return Optional.ofNullable(mapping.get(oauthServerType)) - .orElseThrow(() -> new OauthNotFoundException(OAUTH_SERVER_TYPE_NOT_FOUND)); + .orElseThrow(() -> new OauthNotFoundException(OAUTH_SERVER_TYPE_NOT_FOUND, oauthServerType)); } } diff --git a/backend/src/main/java/com/mapbefine/mapbefine/oauth/domain/OauthMemberClientComposite.java b/backend/src/main/java/com/mapbefine/mapbefine/oauth/domain/OauthMemberClientComposite.java index d932740e..f5fb9648 100644 --- a/backend/src/main/java/com/mapbefine/mapbefine/oauth/domain/OauthMemberClientComposite.java +++ b/backend/src/main/java/com/mapbefine/mapbefine/oauth/domain/OauthMemberClientComposite.java @@ -29,7 +29,7 @@ public OauthMember fetch(OauthServerType oauthServerType, String authCode) { private OauthMemberClient getClient(OauthServerType oauthServerType) { return Optional.ofNullable(mapping.get(oauthServerType)) - .orElseThrow(() -> new OauthNotFoundException(OAUTH_SERVER_TYPE_NOT_FOUND)); + .orElseThrow(() -> new OauthNotFoundException(OAUTH_SERVER_TYPE_NOT_FOUND, oauthServerType)); } } diff --git a/backend/src/main/java/com/mapbefine/mapbefine/oauth/exception/OathException.java b/backend/src/main/java/com/mapbefine/mapbefine/oauth/exception/OathException.java index 6f72b9c4..a18d234c 100644 --- a/backend/src/main/java/com/mapbefine/mapbefine/oauth/exception/OathException.java +++ b/backend/src/main/java/com/mapbefine/mapbefine/oauth/exception/OathException.java @@ -2,12 +2,13 @@ import com.mapbefine.mapbefine.common.exception.ErrorCode; import com.mapbefine.mapbefine.common.exception.NotFoundException; +import com.mapbefine.mapbefine.oauth.domain.OauthServerType; public class OathException { public static class OauthNotFoundException extends NotFoundException { - public OauthNotFoundException(OauthErrorCode errorCode) { - super(new ErrorCode(errorCode.getCode(), errorCode.getMessage())); + public OauthNotFoundException(OauthErrorCode errorCode, OauthServerType oauthServerType) { + super(new ErrorCode<>(errorCode.getCode(), errorCode.getMessage(), oauthServerType)); } } diff --git a/backend/src/main/java/com/mapbefine/mapbefine/permission/application/PermissionCommandService.java b/backend/src/main/java/com/mapbefine/mapbefine/permission/application/PermissionCommandService.java index 9bdec955..1e35500b 100644 --- a/backend/src/main/java/com/mapbefine/mapbefine/permission/application/PermissionCommandService.java +++ b/backend/src/main/java/com/mapbefine/mapbefine/permission/application/PermissionCommandService.java @@ -76,8 +76,9 @@ private boolean isNotSelfMember(AuthMember authMember, Member member) { } private Topic findTopic(PermissionRequest request) { - return topicRepository.findById(request.topicId()) - .orElseThrow(() -> new PermissionBadRequestException(ILLEGAL_TOPIC_ID)); + Long topicId = request.topicId(); + return topicRepository.findById(topicId) + .orElseThrow(() -> new PermissionBadRequestException(ILLEGAL_TOPIC_ID, topicId)); } private void validateMemberCanTopicUpdate(AuthMember authMember, Topic topic) { @@ -93,7 +94,7 @@ private List findTargetMembers(PermissionRequest request) { public void deleteMemberTopicPermission(AuthMember authMember, Long permissionId) { Permission permission = permissionRepository.findById(permissionId) - .orElseThrow(() -> new PermissionBadRequestException(ILLEGAL_PERMISSION_ID)); + .orElseThrow(() -> new PermissionBadRequestException(ILLEGAL_PERMISSION_ID, permissionId)); validateMemberCanTopicUpdate(authMember, permission.getTopic()); diff --git a/backend/src/main/java/com/mapbefine/mapbefine/permission/application/PermissionQueryService.java b/backend/src/main/java/com/mapbefine/mapbefine/permission/application/PermissionQueryService.java index 01a1eafd..7765d151 100644 --- a/backend/src/main/java/com/mapbefine/mapbefine/permission/application/PermissionQueryService.java +++ b/backend/src/main/java/com/mapbefine/mapbefine/permission/application/PermissionQueryService.java @@ -30,7 +30,7 @@ public List findAllTopicPermissions(Long topicId) { public PermissionDetailResponse findPermissionById(Long permissionId) { Permission permission = permissionRepository.findById(permissionId) - .orElseThrow(() -> new PermissionNotFoundException(PERMISSION_NOT_FOUND)); + .orElseThrow(() -> new PermissionNotFoundException(PERMISSION_NOT_FOUND, permissionId)); return PermissionDetailResponse.from(permission); } diff --git a/backend/src/main/java/com/mapbefine/mapbefine/permission/exception/PermissionException.java b/backend/src/main/java/com/mapbefine/mapbefine/permission/exception/PermissionException.java index c0fc7c0b..070691ba 100644 --- a/backend/src/main/java/com/mapbefine/mapbefine/permission/exception/PermissionException.java +++ b/backend/src/main/java/com/mapbefine/mapbefine/permission/exception/PermissionException.java @@ -7,21 +7,21 @@ public class PermissionException { - public static class PermissionForbiddenException extends ForbiddenException { - public PermissionForbiddenException(PermissionErrorCode errorCode) { - super(new ErrorCode(errorCode.getCode(), errorCode.getMessage())); + public static class PermissionBadRequestException extends BadRequestException { + public PermissionBadRequestException(PermissionErrorCode errorCode, Long id) { + super(new ErrorCode<>(errorCode.getCode(), errorCode.getMessage(), id)); } } - public static class PermissionBadRequestException extends BadRequestException { - public PermissionBadRequestException(PermissionErrorCode errorCode) { - super(new ErrorCode(errorCode.getCode(), errorCode.getMessage())); + public static class PermissionForbiddenException extends ForbiddenException { + public PermissionForbiddenException(PermissionErrorCode errorCode) { + super(new ErrorCode<>(errorCode.getCode(), errorCode.getMessage())); } } public static class PermissionNotFoundException extends NotFoundException { - public PermissionNotFoundException(PermissionErrorCode errorCode) { - super(new ErrorCode(errorCode.getCode(), errorCode.getMessage())); + public PermissionNotFoundException(PermissionErrorCode errorCode, Long id) { + super(new ErrorCode<>(errorCode.getCode(), errorCode.getMessage(), id)); } } diff --git a/backend/src/main/java/com/mapbefine/mapbefine/pin/application/PinQueryService.java b/backend/src/main/java/com/mapbefine/mapbefine/pin/application/PinQueryService.java index 223fb5b9..f5a0b23a 100644 --- a/backend/src/main/java/com/mapbefine/mapbefine/pin/application/PinQueryService.java +++ b/backend/src/main/java/com/mapbefine/mapbefine/pin/application/PinQueryService.java @@ -37,7 +37,7 @@ public List findAllReadable(AuthMember member) { // TODO: 2023/08/08 isDeleted 제외하고 조회하기 public PinDetailResponse findDetailById(AuthMember member, Long pinId) { Pin pin = pinRepository.findById(pinId) - .orElseThrow(() -> new PinNotFoundException(PIN_NOT_FOUND)); + .orElseThrow(() -> new PinNotFoundException(PIN_NOT_FOUND, pinId)); validateReadAuth(member, pin.getTopic()); return PinDetailResponse.from(pin); diff --git a/backend/src/main/java/com/mapbefine/mapbefine/pin/exception/PinException.java b/backend/src/main/java/com/mapbefine/mapbefine/pin/exception/PinException.java index a96aa4bc..fa98ffbc 100644 --- a/backend/src/main/java/com/mapbefine/mapbefine/pin/exception/PinException.java +++ b/backend/src/main/java/com/mapbefine/mapbefine/pin/exception/PinException.java @@ -7,26 +7,21 @@ public class PinException { public static class PinBadRequestException extends BadRequestException { - public PinBadRequestException(PinErrorCode errorCode) { - super(new ErrorCode(errorCode.getCode(), errorCode.getMessage())); + super(new ErrorCode<>(errorCode.getCode(), errorCode.getMessage())); } } public static class PinForbiddenException extends ForbiddenException { - public PinForbiddenException(PinErrorCode errorCode) { - super(new ErrorCode(errorCode.getCode(), errorCode.getMessage())); + super(new ErrorCode<>(errorCode.getCode(), errorCode.getMessage())); } } public static class PinNotFoundException extends ForbiddenException { - - public PinNotFoundException(PinErrorCode errorCode) { - super(new ErrorCode(errorCode.getCode(), errorCode.getMessage())); + public PinNotFoundException(PinErrorCode errorCode, Long id) { + super(new ErrorCode<>(errorCode.getCode(), errorCode.getMessage(), id)); } } - - } diff --git a/backend/src/main/java/com/mapbefine/mapbefine/topic/application/TopicQueryService.java b/backend/src/main/java/com/mapbefine/mapbefine/topic/application/TopicQueryService.java index e0cda86c..8619ce4c 100644 --- a/backend/src/main/java/com/mapbefine/mapbefine/topic/application/TopicQueryService.java +++ b/backend/src/main/java/com/mapbefine/mapbefine/topic/application/TopicQueryService.java @@ -122,7 +122,7 @@ public TopicDetailResponse findDetailById(AuthMember authMember, Long topicId) { private Topic findTopic(Long id) { return topicRepository.findById(id) - .orElseThrow(() -> new TopicNotFoundException(TOPIC_NOT_FOUND)); + .orElseThrow(() -> new TopicNotFoundException(TOPIC_NOT_FOUND, List.of(id))); } private void validateReadableTopic(AuthMember member, Topic topic) { @@ -168,9 +168,14 @@ private List getUserTopicDetailResponses(AuthMember authMem } private void validateTopicsCount(List topicIds, List topics) { - if (topicIds.size() != topics.size()) { - throw new TopicNotFoundException(TOPIC_NOT_FOUND); + List nonMatchingIds = topicIds.stream() + .filter(id -> topics.stream().noneMatch(topic -> topic.getId().equals(id))) + .toList(); + + if (nonMatchingIds.isEmpty()) { + return; } + throw new TopicNotFoundException(TOPIC_NOT_FOUND, nonMatchingIds); } private void validateReadableTopics(AuthMember member, List topics) { diff --git a/backend/src/main/java/com/mapbefine/mapbefine/topic/exception/TopicException.java b/backend/src/main/java/com/mapbefine/mapbefine/topic/exception/TopicException.java index 97c890d0..2c2afb9f 100644 --- a/backend/src/main/java/com/mapbefine/mapbefine/topic/exception/TopicException.java +++ b/backend/src/main/java/com/mapbefine/mapbefine/topic/exception/TopicException.java @@ -4,27 +4,24 @@ import com.mapbefine.mapbefine.common.exception.ErrorCode; import com.mapbefine.mapbefine.common.exception.ForbiddenException; import com.mapbefine.mapbefine.common.exception.NotFoundException; +import java.util.List; public class TopicException { - - public static class TopicForbiddenException extends ForbiddenException { - - public TopicForbiddenException(TopicErrorCode errorCode) { - super(new ErrorCode(errorCode.getCode(), errorCode.getMessage())); + public static class TopicBadRequestException extends BadRequestException { + public TopicBadRequestException(TopicErrorCode errorCode) { + super(new ErrorCode<>(errorCode.getCode(), errorCode.getMessage())); } } - public static class TopicBadRequestException extends BadRequestException { - - public TopicBadRequestException(TopicErrorCode errorCode) { - super(new ErrorCode(errorCode.getCode(), errorCode.getMessage())); + public static class TopicForbiddenException extends ForbiddenException { + public TopicForbiddenException(TopicErrorCode errorCode) { + super(new ErrorCode<>(errorCode.getCode(), errorCode.getMessage())); } } public static class TopicNotFoundException extends NotFoundException { - - public TopicNotFoundException(TopicErrorCode errorCode) { - super(new ErrorCode(errorCode.getCode(), errorCode.getMessage())); + public TopicNotFoundException(TopicErrorCode errorCode, List ids) { + super(new ErrorCode<>(errorCode.getCode(), errorCode.getMessage(), ids)); } }