Welcome Guest, Not a member yet? Register   Sign In
Filter - Return response error
#1

Hi,
I have created a filter to trigger a process After a controller.
My controller (below) is very simple. Essentially, the controller receives data from an external source (webhook), assigns a variable to the data, and returns an HTTP 200 (Success) to the external server.

PHP Code:
namespace App\Controllers;

use 
CodeIgniter\Controller;
use 
App\Controllers\BaseController;

class 
Filter_Test extends BaseController {
    public function index() {
       if ($this->request->getJSON()) { 
          $external_data$this->request->getJSON();
          log_message('notice''[SUCCESS] {file}-{line}, JSON ARRAY from EXTERNAL  - '.print_r($external_data,true)); 
       }
       return $this->response->setStatusCode(200);
    }



After the above controller, the filter is executing perfectly, and running my process (below). 
My process (below) obviously fails as $bar does not exist,
PHP Code:
use CodeIgniter\Model;
use 
CodeIgniter\Database\Query;

class 
Updater {
    public function write_data($vals) {
        $foo=$bar;
    }


In this instance, Codeigniter is returning an HTTP 500 response to the external server, instead of the HTTP 200 as defined in the controller.

I do not understand how this is possible as I should have already returned HTTP 200 from the controller, and my process (Updater) should only be called AFTER the controller has finished, is this correct?

If this is not correct, is there a way to respond with HTTP 200 from the controller (this would be correct as I have received the data), and then process the data, handling any subsequent errors (data or framework) in alternative ways?

Many Thanks,
Reply


Messages In This Thread
Filter - Return response error - by 68thorby68 - 08-26-2024, 03:54 AM
RE: Filter - Return response error - by seunex - 08-26-2024, 03:04 PM
RE: Filter - Return response error - by kenjis - 08-26-2024, 03:46 PM
RE: Filter - Return response error - by ozornick - 09-11-2024, 06:37 AM
RE: Filter - Return response error - by kenjis - 09-11-2024, 06:25 PM



Theme © iAndrew 2016 - Forum software by © MyBB