Skip to content

Commit

Permalink
📝 docs: service layer design
Browse files Browse the repository at this point in the history
  • Loading branch information
Zerohertz committed Oct 30, 2024
1 parent 51ddf7c commit 036b722
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 3 deletions.
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
## Docs

- [docker-compose](docs/docker-compose.md)
- [kubernetes](docs/kubernetes.md)
- [package-structure](docs/package-structure.md)
- [Package 구조](docs/package-structure.md)
- [Service layer 개발 방법](docs/service.md)
- [Docker Compose 사용 방법](docs/docker-compose.md)
- [Kubernetes 사용 방법](docs/kubernetes.md)
27 changes: 27 additions & 0 deletions docs/service.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
## Exception Handling

> Service layer의 exception handling은 [`GlobalExceptionHandler`](src/main/java/com/server/global/error/handler/GlobalExceptionHandler.java)를 통해 관리
```java
@RestControllerAdvice
public class GlobalExceptionHandler {

@ExceptionHandler(AuthException.class)
public ResponseEntity<ApiResponseDto<Object>> handleFriendException(AuthException e) {
return ResponseEntity.status(e.getStatus()).body(ApiResponseDto.error(e.getStatus(), e.getMessage()));
}

@ExceptionHandler(BusinessException.class)
public ResponseEntity<ApiResponseDto<Object>> handleFriendException(BusinessException e) {
return ResponseEntity.status(e.getStatus()).body(ApiResponseDto.error(e.getStatus(), e.getMessage()));
}

}
```

> [`ErrorCode`](src/main/java/com/server/global/error/code)[`Exception`](src/main/java/com/server/global/error/exception) 정의 후 아래 예시와 같이 service layer에서 예외 생성
```java
throw new AuthException(AuthErrorCode.OAUTH_PROCESS_ERROR);
throw new BusinessException(FriendErrorCode.RECEIPT_ALREADY_EXISTS);
```

0 comments on commit 036b722

Please sign in to comment.