Welcome Guest, Not a member yet? Register   Sign In
API Response Exception in production environment
#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


Messages In This Thread
RE: API Response Exception in production environment - by kenjis - 06-22-2022, 04:24 PM



Theme © iAndrew 2016 - Forum software by © MyBB