Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
…R-memento into ftix/#116-client-connect
  • Loading branch information
paragon0107 committed Jan 24, 2025
2 parents 4222228 + 5f2e4c6 commit f2a36c3
Show file tree
Hide file tree
Showing 15 changed files with 181 additions and 114 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ public enum ErrorCode {

/* 유효하지 않은 요청 */
INVALID_REQUEST_BODY("유효하지 않은 요청입니다."),
INVALID_ARGUMENT_TYPE("잘못된 매개변수 타입입니다."),
INVALID_JSON_FORMAT("요청 JSON 형식이 올바르지 않습니다."),
DECODING_FAILURE("디코딩 실패로 인해 요청을 처리할 수 없습니다."),

/* 소셜 로그인 관련 에러 */
INVALID_ID_TOKEN("유효하지 않은 ID 토큰입니다."),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,15 @@
import com.official.memento.alarm.service.command.AlarmSendUseCase;
import com.official.memento.global.dto.ErrorResponse;
import com.official.memento.global.exception.*;
import io.jsonwebtoken.io.DecodingException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.http.converter.HttpMessageNotReadableException;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;
import org.springframework.web.method.annotation.MethodArgumentTypeMismatchException;
import org.springframework.web.servlet.resource.NoResourceFoundException;

@RestControllerAdvice
Expand All @@ -29,6 +32,13 @@ public ResponseEntity<ErrorResponse> noResourceFoundException(NoResourceFoundExc
return ErrorResponse.of(HttpStatus.NOT_FOUND, ErrorCode.INTERNAL_SERVER_ERROR);
}

@ExceptionHandler(RuntimeException.class)
public ResponseEntity<ErrorResponse> runtimeException(RuntimeException exception) {
logger.error("Runtime exception occurred ", exception);
alarmSendUseCase.sendException(new AlarmExceptionCommand(exception));
return ErrorResponse.of(HttpStatus.INTERNAL_SERVER_ERROR, ErrorCode.INTERNAL_SERVER_ERROR);
}

@ExceptionHandler(Exception.class)
public ResponseEntity<ErrorResponse> exception(Exception exception) {
logger.error("Unhandled exception occurred ", exception);
Expand All @@ -53,7 +63,6 @@ public ResponseEntity<ErrorResponse> invalidRequestBodyException(InvalidRequestB
@ExceptionHandler(UnauthorizedException.class)
public ResponseEntity<ErrorResponse> unauthorizedException(UnauthorizedException exception) {
logger.error("Unauthorized access attempt", exception);
alarmSendUseCase.sendException(new AlarmExceptionCommand(exception));
return ErrorResponse.of(HttpStatus.UNAUTHORIZED, ErrorCode.UNAUTHORIZED_USER);
}

Expand All @@ -70,4 +79,28 @@ public ResponseEntity<ErrorResponse> nullPointException(NullPointException excep
alarmSendUseCase.sendException(new AlarmExceptionCommand(exception));
return ErrorResponse.of(HttpStatus.NOT_FOUND, ErrorCode.NOT_FOUND_ENTITY);
}

@ExceptionHandler(MethodArgumentTypeMismatchException.class)
public ResponseEntity<ErrorResponse> MethodArgumentTypeMismatchException(MethodArgumentTypeMismatchException exception) {
logger.error("Invalid request:", exception);
return ErrorResponse.of(HttpStatus.BAD_REQUEST, ErrorCode.INVALID_ARGUMENT_TYPE);
}

@ExceptionHandler(DecodingException.class)
public ResponseEntity<ErrorResponse> DecodingException(DecodingException exception) {
logger.error("Invalid request:", exception);
return ErrorResponse.of(HttpStatus.BAD_REQUEST, ErrorCode.DECODING_FAILURE);
}

@ExceptionHandler(HttpMessageNotReadableException.class)
public ResponseEntity<ErrorResponse> HttpMessageNotReadableException(HttpMessageNotReadableException exception) {
logger.error("Invalid request:", exception);
return ErrorResponse.of(HttpStatus.BAD_REQUEST, ErrorCode.INVALID_JSON_FORMAT);
}

@ExceptionHandler(InvalidAiRequestException.class)
public ResponseEntity<ErrorResponse> invalidAiRequestException(InvalidAiRequestException exception) {
logger.error("Invalid AI request:", exception);
return ErrorResponse.of(HttpStatus.BAD_REQUEST, ErrorCode.INVALID_AI_PRIORITIZATION_REQUEST);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,19 @@ public class MemberPersonalInfo {
private Boolean isPreferReminder;
private Boolean isImportantBreaks;


public String toPersonalInfoString() {
return "MemberPersonalInfo" +
", wakeUpTime=" + wakeUpTime +
", windDownTime=" + windDownTime +
", job=" + job +
", stressed unorganized schedule isStressedUnorganizedSchedule=" + isStressedUnorganizedSchedule +
", often forget important things =" + isForgetImportantThings +
", prefer reminders =" + isPreferReminder +
", break is important =" + isImportantBreaks +
'}';
}

public static MemberPersonalInfo of(
final Long memberId)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.official.memento.schedule.conntroller.dto.request;

import com.official.memento.global.entity.enums.RepeatOption;
import com.official.memento.global.exception.InvalidRequestBodyException;
import com.official.memento.global.exception.NullPointException;
import io.swagger.v3.oas.annotations.media.Schema;

Expand Down Expand Up @@ -57,7 +58,7 @@ private static void checkNullData(
final String scheduleGroupId
) {
if (description == null | startDate == null || endDate == null || repeatOption == null || scheduleGroupId == null) {
throw new NullPointException(NULL_DATA_ERROR);
throw new InvalidRequestBodyException(NULL_DATA_ERROR);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.official.memento.schedule.conntroller.dto.request;

import com.official.memento.global.exception.InvalidRequestBodyException;
import com.official.memento.global.exception.NullPointException;
import io.swagger.v3.oas.annotations.media.Schema;

Expand Down Expand Up @@ -37,7 +38,7 @@ private static void checkNullData(
final LocalDateTime endDate
) {
if (description == null | startDate == null || endDate == null) {
throw new NullPointException(NULL_DATA_ERROR);
throw new InvalidRequestBodyException(NULL_DATA_ERROR);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.official.memento.schedule.service.command;

import com.official.memento.global.entity.enums.RepeatOption;
import com.official.memento.global.exception.InvalidRequestBodyException;
import com.official.memento.global.exception.NullPointException;

import java.time.LocalDate;
Expand Down Expand Up @@ -48,7 +49,7 @@ private static void checkNullData(
final RepeatOption repeatOption
) {
if (description == null | startDate == null || endDate == null || repeatOption == null) {
throw new NullPointException(NULL_DATA_ERROR);
throw new InvalidRequestBodyException(NULL_DATA_ERROR);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.official.memento.schedule.service.command;

import com.official.memento.global.exception.InvalidRequestBodyException;
import com.official.memento.global.exception.NullPointException;

import java.time.LocalDateTime;
Expand Down Expand Up @@ -39,7 +40,7 @@ private static void checkNullData(
final LocalDateTime endDate
) {
if (description == null | startDate == null || endDate == null) {
throw new NullPointException(NULL_DATA_ERROR);
throw new InvalidRequestBodyException(NULL_DATA_ERROR);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.official.memento.todo.controller.dto;

import com.official.memento.global.entity.enums.RepeatOption;
import com.official.memento.global.exception.InvalidRequestBodyException;
import com.official.memento.global.exception.NullPointException;
import io.swagger.v3.oas.annotations.media.Schema;

Expand Down Expand Up @@ -45,7 +46,7 @@ private static void checkNullData(
final String description
) {
if (startDate == null || description == null) {
throw new NullPointException(NULL_DATA_ERROR);
throw new InvalidRequestBodyException(NULL_DATA_ERROR);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.official.memento.todo.controller.dto;

import com.official.memento.global.exception.InvalidRequestBodyException;
import com.official.memento.global.exception.NullPointException;
import io.swagger.v3.oas.annotations.media.Schema;

Expand Down Expand Up @@ -39,7 +40,7 @@ private static void checkNullData(
final String description
) {
if (startDate == null || description == null) {
throw new NullPointException(NULL_DATA_ERROR);
throw new InvalidRequestBodyException(NULL_DATA_ERROR);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@ interface ClaudeAiChatClientOutputPort {
fun prioritizeTodo(
todoList: List<ToDo>,
orderList: List<Int>,
personalInfo: String
): List<PrioritizedToDo>
}
Loading

0 comments on commit f2a36c3

Please sign in to comment.