Here is my global exception handler written in Spring Boot
data class ErrorResponse(
val status: Int? = null,
val message: String? = null
)
@ControllerAdvice
class GlobalExceptionHandler {
@ExceptionHandler(ItemAlreadyExistsException::class)
fun handleItemAlreadyExistsException(e: ItemAlreadyExistsException?): ResponseEntity<ErrorResponse> =
ResponseEntity(ErrorResponse(HttpStatus.CONFLICT.value(), e?.message.toString()), HttpStatus.CONFLICT)
}
And here is my useMutation function
const useSignUp = useMutation<Employer, Error, Employer>(
(employer) => signUpAsEmployer(employer),
{
onError: (error) => {
console.log(error.message)
}
}
);
How can I console log the custom message from thrown Exception?
console.log(error.message) gives me: "Request failed with status code 409" while I want the message I marked by arrow on the image
