Skip to content

Commit

Permalink
feat: handle connectionexception
Browse files Browse the repository at this point in the history
  • Loading branch information
seyedali-dev committed Jun 15, 2024
1 parent d84d751 commit 8d55f00
Showing 1 changed file with 12 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import com.seyed.ali.timeentryservice.exceptions.OperationNotSupportedException;
import com.seyed.ali.timeentryservice.exceptions.ResourceNotFoundException;
import com.seyed.ali.timeentryservice.model.payload.response.Result;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.http.converter.HttpMessageNotReadableException;
import org.springframework.security.access.AccessDeniedException;
Expand All @@ -14,6 +15,7 @@
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

import java.net.ConnectException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -53,6 +55,16 @@ public ResponseEntity<Result> handleOperationNotSupportedException(OperationNotS
));
}

@ExceptionHandler({ConnectException.class})
public ResponseEntity<Result> handleConnectException(ConnectException e) {
return ResponseEntity.status(SERVICE_UNAVAILABLE).body(new Result(
false,
SERVICE_UNAVAILABLE,
"The service is not available 👎🏻",
"ServerMessage 🚫 - " + e.getMessage()
));
}

@ExceptionHandler({MethodArgumentNotValidException.class})
public ResponseEntity<Result> handleMethodArgumentNotValidException(MethodArgumentNotValidException e) {
List<ObjectError> allErrors = e.getBindingResult().getAllErrors();
Expand Down

0 comments on commit 8d55f00

Please sign in to comment.