Skip to content

Commit

Permalink
[FEAT/#20] JsonConverter 에러 CustomException로 처리
Browse files Browse the repository at this point in the history
  • Loading branch information
ckkim817 committed Jul 10, 2024
1 parent b7a2f22 commit cb30459
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import org.sopt.seonyakServer.global.exception.enums.ErrorType;
import org.sopt.seonyakServer.global.exception.model.CustomException;

@Converter
public class JsonConverter implements AttributeConverter<Map<String, Object>, String> {
Expand All @@ -18,7 +20,7 @@ public String convertToDatabaseColumn(Map<String, Object> attribute) {
try {
return objectMapper.writeValueAsString(attribute);
} catch (JsonProcessingException e) {
throw new RuntimeException("Error converting map to JSON string.", e);
throw new CustomException(ErrorType.MAP_TO_JSON_ERROR);
}
}

Expand All @@ -27,7 +29,7 @@ public Map<String, Object> convertToEntityAttribute(String dbData) {
try {
return objectMapper.readValue(dbData, HashMap.class);
} catch (IOException e) {
throw new RuntimeException("Error converting JSON string to map.", e);
throw new CustomException(ErrorType.JSON_TO_MAP_ERROR);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ public enum ErrorType {
INVALID_CODE_HEADER_ERROR(HttpStatus.BAD_REQUEST, "40007", "code 헤더값의 형식이 잘못되었습니다."),
INVALID_SOCIAL_TYPE_ERROR(HttpStatus.BAD_REQUEST, "40008", "유효하지 않은 Social Type입니다."),
BEARER_LOST_ERROR(HttpStatus.BAD_REQUEST, "40009", "요청한 토큰이 Bearer 토큰이 아닙니다."),
MAP_TO_JSON_ERROR(HttpStatus.BAD_REQUEST, "40016", "Map을 JSON 문자열로 변환하는 중 오류가 발생했습니다."),
JSON_TO_MAP_ERROR(HttpStatus.BAD_REQUEST, "40017", "JSON 문자열을 Map으로 변환하는 중 오류가 발생했습니다."),

// S3 관련 오류
IMAGE_EXTENSION_ERROR(HttpStatus.BAD_REQUEST, "40051", "이미지 확장자는 jpg, png, webp만 가능합니다."),
Expand Down

0 comments on commit cb30459

Please sign in to comment.