Welcome Guest, Not a member yet? Register   Sign In
API Response Exception in production environment
#1

I can't return a response in the API when a try catch exception occurs.
It always returns a blank response.
 Is it possible to return a json in an exception in the API Response Trait in the production environment?


[Image: QI4S3WK.png]
Reply
#2

Quote: Is it possible to return a json in an exception in the API Response Trait in the production environment?

Yes.

PHP Code:
<?php

namespace App\Controllers;

use 
CodeIgniter\API\ResponseTrait;
use 
Exception;

class 
Home extends BaseController
{
    use ResponseTrait;

    public function index()
    {
        try {
            throw new Exception('Exception.');
        } catch (Exception $e) {
            return $this->failServerError('Server Error.');
        }
    }


Code:
bash-3.2$ curl http://localhost:8080/
{"status":500,"error":500,"messages":{"error":"Server Error."}}
Reply




Theme © iAndrew 2016 - Forum software by © MyBB