Skip to content

Commit

Permalink
feat: implement handlePhotoBrandNotExistsException in WebExceptionHan…
Browse files Browse the repository at this point in the history
…dler
  • Loading branch information
gmkim20713 committed Oct 25, 2024
1 parent f07d002 commit 88a73af
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import kr.mafoo.photo.controller.dto.response.ErrorResponse;
import kr.mafoo.photo.exception.DomainException;
import kr.mafoo.photo.exception.ErrorCode;
import kr.mafoo.photo.exception.PhotoBrandNotExistsException;
import kr.mafoo.photo.service.SlackService;
import lombok.RequiredArgsConstructor;
import org.slf4j.Logger;
Expand Down Expand Up @@ -61,6 +62,26 @@ public ResponseEntity<ErrorResponse> validException(Exception ex) {
.body(response);
}

@ExceptionHandler(PhotoBrandNotExistsException.class)
public Mono<ResponseEntity<ErrorResponse>> handlePhotoBrandNotExistsException(ServerWebExchange exchange, PhotoBrandNotExistsException exception) {
String method = extractMethod(exchange);
String userAgent = extractUserAgent(exchange);
String fullPath = extractURI(exchange);
String originIp = extractOriginIp(exchange);

return extractRequestBody(exchange).flatMap(requestBody -> {
logException(method, fullPath, originIp, userAgent, exception);

return slackService.sendQrRelatedErrorNotification(
method, fullPath, requestBody, originIp, userAgent, exception.getMessage()
).then(Mono.just(
ResponseEntity
.badRequest()
.body(ErrorResponse.fromErrorCode(exception.getErrorCode()))
));
});
}

@ExceptionHandler(ResponseStatusException.class)
public Mono<ResponseEntity<String>> handleResponseStatusException(ServerWebExchange exchange, ResponseStatusException exception) {
return handleExceptionInternal(exchange, exception, (HttpStatus) exception.getStatusCode());
Expand Down
3 changes: 2 additions & 1 deletion photo-service/src/main/resources/application.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,5 @@ slack:
webhook:
token: ${SLACK_TOKEN}
channel:
error: ${SLACK_ERROR_CHANNEL}
error: ${SLACK_ERROR_CHANNEL}
qr: ${SLACK_QR_ERROR_CHANNEL}

0 comments on commit 88a73af

Please sign in to comment.