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/mailtest #65

Merged
merged 2 commits into from
Jul 2, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
4 changes: 2 additions & 2 deletions .github/workflows/cicd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ name: cicd
on:
pull_request:
branches: [ "main" ]
push:
branches: [ "main" ]
# push:
# branches: [ "main" ]

jobs:
build:
Expand Down
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.6-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.7-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,9 @@ public class MailController {

@GetMapping("/mails")
public ResponseEntity<SuccessResponse<?>> getMail(@MemberId Long memberId, @RequestParam String type) {
MailList mailList;

mailList = mailService.getMail(memberId,type);
return SuccessResponse.ok(mailList);
mailService.getMail(memberId,type);
return SuccessResponse.ok(null);
}

@GetMapping("/header")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public class MailService {
private final MemberRepository memberRepository;
private final Pattern pattern = Pattern.compile("<(.*?)>");

public MailList getMail(Long memberId, String type) {;
public void getMail(Long memberId, String type) {;
PlatformType platformType =getEnumPlatformTypeFromStringPlatformType(type);
Member member = memberRepository.findById(memberId)
.orElseThrow(() -> new RuntimeException("Member not found"));
Expand All @@ -69,7 +69,7 @@ public class MailService {
throw new IllegalArgumentException("Unsupported platform type");
}

return mailSetting(memberId, host, id, password, platformType);
mailSetting(memberId, host, id, password, platformType);
}

@Transactional
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/com/Nunbody/global/error/ErrorCode.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ public enum ErrorCode {
*/
MEMBER_NOT_FOUND(HttpStatus.NOT_FOUND, "존재하지 않는 회원입니다."),
ENTITY_NOT_FOUND(HttpStatus.NOT_FOUND, "엔티티를 찾을 수 없습니다."),
/**
* 405 Method Not Allowed
*/
METHOD_NOT_ALLOWED(HttpStatus.METHOD_NOT_ALLOWED, "잘못된 HTTP method 요청입니다."),
/**
* 409 Conflict
*/
Expand Down
37 changes: 0 additions & 37 deletions src/main/java/com/Nunbody/global/error/ErrorResponse.java

This file was deleted.

23 changes: 23 additions & 0 deletions src/main/java/com/Nunbody/global/error/dto/ErrorResponse.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package com.Nunbody.global.error.dto;

import com.Nunbody.global.error.ErrorCode;
import lombok.AccessLevel;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;


@AllArgsConstructor(access = AccessLevel.PRIVATE)
@Builder
@Getter
public class ErrorResponse {
private int status;
private String message;

public static ErrorResponse of(ErrorCode errorCode) {
return ErrorResponse.builder()
.status(errorCode.getHttpStatus().value())
.message(errorCode.getMessage())
.build();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
package com.Nunbody.global.error.exception.handler;

import com.Nunbody.global.error.ErrorCode;
import com.Nunbody.global.error.dto.ErrorResponse;
import com.Nunbody.global.error.exception.BusinessException;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.validation.BindException;
import org.springframework.web.HttpRequestMethodNotSupportedException;
import org.springframework.web.bind.MethodArgumentNotValidException;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.method.annotation.MethodArgumentTypeMismatchException;

@Slf4j
@ControllerAdvice
public class GlobalExceptionHandler {
/**
* Valid & Validated annotation의 binding error를 handling합니다.
*/
@ExceptionHandler(MethodArgumentNotValidException.class)
protected ResponseEntity<ErrorResponse> handleMethodArgumentNotValidException(MethodArgumentNotValidException e) {
log.error(">>> handle: MethodArgumentNotValidException ", e);
final ErrorResponse errorBaseResponse = ErrorResponse.of(ErrorCode.BAD_REQUEST);
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(errorBaseResponse);
}

/**
* ModelAttribute annotation의 binding error를 handling합니다.
*/
@ExceptionHandler(BindException.class)
protected ResponseEntity<ErrorResponse> handleBindException(BindException e) {
log.error(">>> handle: BindException ", e);
final ErrorResponse errorBaseResponse = ErrorResponse.of(ErrorCode.BAD_REQUEST);
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(errorBaseResponse);
}

/**
* RequestParam annotation의 binding error를 handling합니다.
*/
@ExceptionHandler(MethodArgumentTypeMismatchException.class)
protected ResponseEntity<ErrorResponse> handleMethodArgumentTypeMismatchException(MethodArgumentTypeMismatchException e) {
log.error(">>> handle: MethodArgumentTypeMismatchException ", e);
final ErrorResponse errorBaseResponse = ErrorResponse.of(ErrorCode.BAD_REQUEST);
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(errorBaseResponse);
}

/**
* 지원하지 않는 HTTP method로 요청 시 발생하는 error를 handling합니다.
*/
@ExceptionHandler(HttpRequestMethodNotSupportedException.class)
protected ResponseEntity<ErrorResponse> handleHttpRequestMethodNotSupportedException(HttpRequestMethodNotSupportedException e) {
log.error(">>> handle: HttpRequestMethodNotSupportedException ", e);
final ErrorResponse errorBaseResponse = ErrorResponse.of(ErrorCode.METHOD_NOT_ALLOWED);
return ResponseEntity.status(HttpStatus.METHOD_NOT_ALLOWED).body(errorBaseResponse);
}

/**
* BusinessException을 handling합니다.
*/
@ExceptionHandler(BusinessException.class)
protected ResponseEntity<ErrorResponse> handleBusinessException(final BusinessException e) {
log.error(">>> handle: BusinessException ", e);
final ErrorCode errorCode = e.getErrorCode();
final ErrorResponse errorBaseResponse = ErrorResponse.of(errorCode);
return ResponseEntity.status(errorCode.getHttpStatus()).body(errorBaseResponse);
}

/**
* 위에서 정의한 Exception을 제외한 모든 예외를 handling합니다.
*/
@ExceptionHandler(Exception.class)
protected ResponseEntity<ErrorResponse> handleException(Exception e) {
log.error(">>> handle: Exception ", e);
final ErrorResponse errorBaseResponse = ErrorResponse.of(ErrorCode.INTERNAL_SERVER_ERROR);
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(errorBaseResponse);
}
}

Loading