0

I'm receiving a strange error from my call to query() the database. This normally wouldn't be a problem, except that it seems that the query call is redirecting me to the 500 server error page and not executing the rest of my code.

Regardless of the error, this PHP is executed during an AJAX call, meaning that I'm unable to return a properly formatted json string containing the error because CakePHP is redirecting.

A workaround would be to just parse the big HTML response from the server if there is an error, and use javascript to figure out what went wrong and display it properly, but I would much rather return a little json string from the backend that plays nicely with the code I already have in place.

Here is my call:

$this->FileUpload->query('exec sproc_runjob_ProcessTests', false);

Any help would be much appreciated. Thanks in advance!

Community
  • 1
  • 1
Erty Seidohl
  • 4,487
  • 3
  • 33
  • 45

1 Answers1

1

As bfavaretto mentions above, the correct answer is to surround the query line in a try catch.

Here is the code I used:

try{
    $this->dbParent->FileUpload->query('exec sproc_runjob_ProcessTests', false);
} catch(PDOException $e){
    if($e['errorInfo'][0] == 42000 && $e['errorInfo'][1] == 22022)
        return array('error' => 'sproc_blocked');
}
return array('success'=>true);
Community
  • 1
  • 1
Erty Seidohl
  • 4,487
  • 3
  • 33
  • 45