FhcApi Controller: new helper functions

This commit is contained in:
cgfhtw
2024-02-19 15:23:43 +01:00
parent 469b3e9833
commit 013664db70
+28 -1
View File
@@ -98,7 +98,7 @@ class FHCAPI_Controller extends FHC_Controller
/**
* @param array $data
* @param string (optional) $type
* @param string $type (optional)
* @return void
*/
public function addError($data, $type = null)
@@ -171,6 +171,33 @@ class FHCAPI_Controller extends FHC_Controller
exit;
}
/**
* @param array $error
* @param string $type (optional)
* @return void
*/
protected function terminateWithError($error, $type = null)
{
$this->output->set_status_header(REST_Controller::HTTP_INTERNAL_SERVER_ERROR);
$this->addError($error, $type);
$this->setStatus(self::STATUS_ERROR);
exit;
}
/**
* @param stdclass $result
* @param string $errortype
* @return void
*/
protected function checkForErrors($result, $errortype = self::ERROR_TYPE_GENERAL)
{
// TODO(chris): IMPLEMENT!
if (isError($result)) {
$this->terminateWithError(getError($result), $errortype);
}
return $result->retval;
}
// TODO(chris): complete list