Welcome Guest, Not a member yet? Register   Sign In
set404Override - JSON not working
#1

I'm creating a RESTFUl API with JWT. The allowed method is POST, which I've setup in Routes.php. So when end use request with other than "POST" method will end up as 404. I have tried to changed in Routes.php as follows:

PHP Code:
$routes->set404Override('App\Controllers\ErrorController::index'); 
and this is my Controller:

Code:
<?php

namespace App\Controllers;

use App\Controllers\BaseController;
use CodeIgniter\HTTP\ResponseInterface;
use Config\Services;

class ErrorController extends BaseController
{
    public function index()
    {
        return Services::response()
            ->setJSON([
                'status_code' => ResponseInterface::HTTP_NOT_FOUND,
                'status_message' => 'Unknown method'
            ]);
    }
}

But I test in POSTMAN, it return empty or blank. How can I return JSON in custom 404?
Reply


Messages In This Thread
set404Override - JSON not working - by azmanishak - 02-15-2022, 12:33 AM
RE: set404Override - JSON not working - by iRedds - 02-15-2022, 08:08 AM



Theme © iAndrew 2016 - Forum software by © MyBB