Обработка ошибки проверки электронной почты для API

I was facing exactly the same issue I fixed this in the following way by using exception handling, open app/Exceptions/Handler.php

 public function render($request, Throwable $exception)
    {
        Log::error('Http Exception', [
            'exception' => $exception
        ]);
        if ($this->isHttpException($exception)) {
            switch ($exception->getStatusCode()) {
                    // not authorized
                case '403':
                    return self::errorResponse($exception->getMessage(), 403);
                    break;
                    // not found
                case '404':
                    return  self::errorResponse($exception->getMessage(), 404);
                    break;
                    // internal error
                case '500':
                    return  self::errorResponse($exception->getMessage(), 500);
                    break;
                default:
                    return  self::errorResponse("Handler has returned an error", 502);
                    break;
            }
        } else {
            return  self::errorResponse("Something is going wrong we are working on it", 503);
        }
        return parent::render($request, $exception); // TODO: Change the autogenerated stub
    }

    public function errorResponse($message, $code)
    {
        return response()->json([
            'status' => false,
            'message' => $message,
            'data' => [],
            'code' => $code
        ]);
    }
shafeeque