Search
 
SCRIPT & CODE EXAMPLE
 

PHP

Handling Email Verification Error for APIs

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
        ]);
    }
Comment

PREVIOUS NEXT
Code Example
Php :: back to same page after changing locale 
Php :: how to create pdf with doompdf in php 
Php :: php echo to stderr 
Php :: Display out of stock products last (even after sort) - Woocommerce 
Php :: php iterate through objects 
Php :: Return the union of this RDD and another one 
Php :: Set Countries To Appear At The Top Of The Caldera Forms Phone Field List 
Php :: laravel not rollback even has error 
Php :: Compare current time with another time in PHP 
Php :: how to refresh a php variable without reloading page 
Php :: laravel save without dispatching an event 
Php :: list bulan php 
Php :: how to call a function in model from a controller 
Php :: <?php $a=2; if ($a1){ echo "more that 1"; }elseif{ echo "less than one"; } ? 
Php :: data showing in single option instead of multiple option from json array 
Php :: Multi-idiomas com PHP 
Php :: add variables to line in laravel notification 
Php :: How to add watermark in FPDF PHP - Parte 2 
Php :: how to get only file orginal extension in codeigniter 3 
Php :: php if simple 
Php :: find common value from sub arrays 
Php :: insert three bars in php that are used to minimize and maximize pages 
Php :: desactivar estilos globales wordpress 5.9 
Php :: old codestar checkbox field 
Php :: many to many relationship in laravel example stackoverflow 
Php :: php get long word in array 
Php :: register column types octobercms 
Php :: curl outline in laravel 
Php :: creating unique number adding zero 0 in number 
Php :: php print products with attribute 
ADD CONTENT
Topic
Content
Source link
Name
3+7 =