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

#150 [feat] 예외 리턴 값 수정 #231

Merged
merged 1 commit into from
Oct 12, 2023
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,12 @@
import com.asap.server.controller.dto.response.HostLoginResponseDto;
import com.asap.server.exception.Error;
import com.asap.server.exception.model.AsapException;
import com.asap.server.exception.model.BadRequestException;
import com.asap.server.exception.model.ConflictException;
import com.asap.server.exception.model.ForbiddenException;
import com.asap.server.exception.model.HostTimeForbiddenException;
import com.asap.server.exception.model.NotFoundException;
import com.asap.server.exception.model.UnauthorizedException;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.HttpStatus;
Expand Down Expand Up @@ -50,12 +55,6 @@ protected ErrorResponse handleMethodArgumentNotValidException(final MethodArgume
else return ErrorResponse.error(Error.VALIDATION_REQUEST_MISSING_EXCEPTION, fieldError.getDefaultMessage());
}

@ResponseStatus(HttpStatus.NOT_FOUND)
@ExceptionHandler(NoHandlerFoundException.class)
public ErrorResponse handleNotFoundException(NoHandlerFoundException exception) {
return ErrorResponse.error(Error.URI_NOT_FOUND_EXCEPTION);
}

@ResponseStatus(HttpStatus.BAD_REQUEST)
@ExceptionHandler(HttpMessageNotReadableException.class)
protected ErrorResponse handleJsonParseException(final HttpMessageNotReadableException e) {
Expand All @@ -68,61 +67,71 @@ protected ErrorResponse handleValidationException(final ConstraintViolationExcep
return ErrorResponse.error(Error.VALIDATION_REQUEST_MISSING_EXCEPTION);
}


@ResponseStatus(HttpStatus.BAD_REQUEST)
@ExceptionHandler(BadRequestException.class)
protected ErrorResponse handleBadRequestException(final BadRequestException e) {
return ErrorResponse.error(e.getError());
}

/**
* 405 Method Not Allowed
* 지원하지 않은 HTTP method 호출 할 경우 발생하는 Exception
* 401 UnAuthorization
*/
@ResponseStatus(HttpStatus.METHOD_NOT_ALLOWED)
@ExceptionHandler(HttpRequestMethodNotSupportedException.class)
protected ErrorResponse handleHttpRequestMethodNotSupportedException(
HttpRequestMethodNotSupportedException exception) {
return ErrorResponse.error(METHOD_NOT_ALLOWED_EXCEPTION);
@ResponseStatus(HttpStatus.UNAUTHORIZED)
@ExceptionHandler(UnauthorizedException.class)
protected ErrorResponse handleUnAuthorizedException(final UnauthorizedException e) {
return ErrorResponse.error(e.getError());
}

// /**
// * 401 UnAuthorization
// */
// @ResponseStatus(HttpStatus.UNAUTHORIZED)
// @ExceptionHandler(UnauthorizedException.class)
// protected ErrorResponse handleUnAuthorizedException(final UnauthorizedException e) {
// return ErrorResponse.error(e.getError());
// }
//
// /**
// * 403 Forbidden
// */
// @ResponseStatus(HttpStatus.FORBIDDEN)
// @ExceptionHandler(ForbiddenException.class)
// protected ErrorResponse handleForbiddenException(final ForbiddenException e) {
// return ErrorResponse.error(e.getError());
// }

/**
* 403 Forbidden
*/
@ResponseStatus(HttpStatus.FORBIDDEN)
@ExceptionHandler(ForbiddenException.class)
protected ErrorResponse handleForbiddenException(final ForbiddenException e) {
return ErrorResponse.error(e.getError());
}

@ResponseStatus(HttpStatus.FORBIDDEN)
@ExceptionHandler(HostTimeForbiddenException.class)
protected ErrorDataResponse<HostLoginResponseDto> handleForbiddenException(final HostTimeForbiddenException e) {
return ErrorDataResponse.error(e.getError(), e.getMessage(), e.getData());
}

// /**
// * 404 Not Found
// */
// @ResponseStatus(HttpStatus.NOT_FOUND)
// @ExceptionHandler(NotFoundException.class)
// protected ErrorResponse handleNotFoundException(final NotFoundException e) {
// return ErrorResponse.error(e.getError());
// }
/**
* 404 Not Found
*/
@ResponseStatus(HttpStatus.NOT_FOUND)
@ExceptionHandler(NotFoundException.class)
protected ErrorResponse handleNotFoundException(final NotFoundException e) {
return ErrorResponse.error(e.getError());
}

@ResponseStatus(HttpStatus.NOT_FOUND)
@ExceptionHandler(NoHandlerFoundException.class)
public ErrorResponse handleNotFoundException(NoHandlerFoundException exception) {
return ErrorResponse.error(Error.URI_NOT_FOUND_EXCEPTION);
}

/**
* 405 Method Not Allowed
* 지원하지 않은 HTTP method 호출 할 경우 발생하는 Exception
*/
@ResponseStatus(HttpStatus.METHOD_NOT_ALLOWED)
@ExceptionHandler(HttpRequestMethodNotSupportedException.class)
protected ErrorResponse handleHttpRequestMethodNotSupportedException(
HttpRequestMethodNotSupportedException exception) {
return ErrorResponse.error(METHOD_NOT_ALLOWED_EXCEPTION);
}

/**
* 409 Conflict
*/
// @ResponseStatus(HttpStatus.CONFLICT)
// @ExceptionHandler(ConflictException.class)
// protected ErrorResponse handleConflictException(final ConflictException e) {
// return ErrorResponse.error(e.getError());
// }
@ResponseStatus(HttpStatus.CONFLICT)
@ExceptionHandler(ConflictException.class)
protected ErrorResponse handleConflictException(final ConflictException e) {
return ErrorResponse.error(e.getError());
}

/**
* 500 Internal Server
Expand Down