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

[4기 황창현] URL Shortener 과제 제출 #40

Open
wants to merge 28 commits into
base: changhyeonh
Choose a base branch
from
Open
Changes from 1 commit
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
e94b801
feat: 입력 폼 페이지 구현
Hchanghyeon Oct 1, 2023
5219f38
build: validation 의존성 추가
Hchanghyeon Oct 1, 2023
443a96a
feat: 분리되어있던 페이지 통합, 프론트엔드 구현
Hchanghyeon Oct 3, 2023
910b678
build: JPA, H2 Database 사용을 위한 yml파일 설정
Hchanghyeon Oct 3, 2023
b2e7a79
chore: 페이지를 통합하면서 필요 없는 페이지 삭제
Hchanghyeon Oct 3, 2023
ab6fdfe
feat: Url 도메인 구현
Hchanghyeon Oct 3, 2023
6233638
feat: JpaAudting 기능 추가
Hchanghyeon Oct 3, 2023
3fde736
feat: 10진수를 Base62로 변환하는 컨버터 생성
Hchanghyeon Oct 3, 2023
9a77c4f
feat: URL을 검증하는 Validator 구현
Hchanghyeon Oct 3, 2023
5b17cb3
feat: Url Repository 생성 및 Lock과 기본 조회 로직 구현
Hchanghyeon Oct 3, 2023
df14a51
feat: Url Service 로직 구현
Hchanghyeon Oct 3, 2023
0ff6b6b
feat: Url Controller 로직 구현
Hchanghyeon Oct 3, 2023
74b2b14
feat: WebConfig로 ViewController 설정
Hchanghyeon Oct 3, 2023
8a92e3a
feat: 예외 처리 구현
Hchanghyeon Oct 3, 2023
5210f20
chore: 불필요한 테스트 코드 삭제
Hchanghyeon Oct 3, 2023
1246112
test: Repository, Domain 테스트 구현
Hchanghyeon Oct 3, 2023
14f5a61
style: class import
Hchanghyeon Oct 3, 2023
3554631
feat: Url 도메인 null 예외처리
Hchanghyeon Oct 3, 2023
b4828f1
style: 개행 처리
Hchanghyeon Oct 3, 2023
88552d9
style: 페이지에서 MD5 알고리즘 삭제
Hchanghyeon Oct 3, 2023
413974e
style: 개행 삭제
Hchanghyeon Oct 3, 2023
c24d8ca
refactor: IP DTO에서 받지 않도록 변경
Hchanghyeon Oct 11, 2023
dd539b5
refactor: unique로 변경
Hchanghyeon Oct 11, 2023
de6991e
style: ViewCount로 이름 변경
Hchanghyeon Oct 11, 2023
1ced81b
refactor: 분기문이 아닌 Enum에서 처리
Hchanghyeon Oct 11, 2023
4e45131
refactor: 빈 생성자 삭제
Hchanghyeon Oct 11, 2023
55b4a31
refactor: 비관적 락 적용 삭제
Hchanghyeon Oct 11, 2023
9fd79f2
refactor: column default 값 설정
Hchanghyeon Oct 11, 2023
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
Prev Previous commit
Next Next commit
feat: 예외 처리 구현
Hchanghyeon committed Oct 3, 2023
commit 8a92e3aafa1971db80d7001ca3a3d5a914e41775
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.programmers.urlshortener.common.exception;

import org.springframework.http.HttpStatus;

import lombok.Getter;

@Getter
public class BusinessException extends RuntimeException {

private HttpStatus status;
private String message;

protected BusinessException(ExceptionRule exceptionRule) {
super(exceptionRule.getMessage());
this.status = exceptionRule.getStatus();
this.message = exceptionRule.getMessage();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.programmers.urlshortener.common.exception;

import lombok.AccessLevel;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;

@Getter
@NoArgsConstructor(access = AccessLevel.PROTECTED)
public class ErrorResponse {

private int statusCode;
private String message;

@Builder
private ErrorResponse(int statusCode, String message) {
this.statusCode = statusCode;
this.message = message;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.programmers.urlshortener.common.exception;

import org.springframework.http.HttpStatus;

import lombok.Getter;
import lombok.RequiredArgsConstructor;

@Getter
@RequiredArgsConstructor
public enum ExceptionRule {

SHORTENURL_NOT_EXIST(HttpStatus.NOT_FOUND, "해당 URL은 단축된 URL 목록에서 찾을 수 없습니다."),
NOT_FOUND(HttpStatus.NOT_FOUND, "요청하신 URL은 없는 URL입니다."),
BAD_REQUEST(HttpStatus.BAD_REQUEST, "잘못된 요청입니다. 입력 값을 다시 확인해주세요."),
INTERNAL_SERVER_ERROR(HttpStatus.INTERNAL_SERVER_ERROR, "서버에서 알 수 없는 오류가 발생했습니다. 관리자에게 문의해주세요."),
;

private final HttpStatus status;
private final String message;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
package com.programmers.urlshortener.common.exception;

import static com.programmers.urlshortener.common.exception.ExceptionRule.*;

import java.util.List;

import org.springframework.http.ResponseEntity;
import org.springframework.validation.FieldError;
import org.springframework.web.bind.MethodArgumentNotValidException;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

import lombok.extern.slf4j.Slf4j;

@Slf4j
@RestControllerAdvice
public class GlobalExceptionHandler {

@ExceptionHandler(MethodArgumentNotValidException.class)
public ResponseEntity<ErrorResponse> handleMethodArgumentNotValidException(MethodArgumentNotValidException e) {
List<FieldError> errors = e.getBindingResult()
.getAllErrors()
.stream()
.map(FieldError.class::cast)
.toList();

log.error("[에러]: {}", e.getMessage(), e);

errors.forEach(
error -> log.error("메시지: {} / 원인: {} : {}", error.getDefaultMessage(), error.getField(),
error.getRejectedValue()));

ErrorResponse errorResponse = ErrorResponse.builder()
.statusCode(BAD_REQUEST.getStatus().value())
.message(BAD_REQUEST.getMessage())
.build();

return ResponseEntity.status(BAD_REQUEST.getStatus()).body(errorResponse);
}

@ExceptionHandler(BusinessException.class)
public ResponseEntity<ErrorResponse> handleBusinessException(BusinessException e) {
log.error("[에러]: {}", e.getMessage(), e);

ErrorResponse errorResponse = ErrorResponse.builder()
.statusCode(e.getStatus().value())
.message(e.getMessage())
.build();

return ResponseEntity.status(e.getStatus()).body(errorResponse);
}

@ExceptionHandler(Exception.class)
public ResponseEntity<ErrorResponse> handleException(Exception e) {
log.error("[에러]: {}", e.getMessage(), e);

ErrorResponse errorResponse = ErrorResponse.builder()
.statusCode(INTERNAL_SERVER_ERROR.getStatus().value())
.message(INTERNAL_SERVER_ERROR.getMessage())
.build();

return ResponseEntity.status(INTERNAL_SERVER_ERROR.getStatus()).body(errorResponse);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.programmers.urlshortener.common.exception;

public class UrlException extends BusinessException {

public UrlException(ExceptionRule exceptionRule) {
super(exceptionRule);
}
}