Webiny\Component\Rest\Response\CallbackResult::setErrorResponse PHP Method

setErrorResponse() public method

Adds a general error to the response.
public setErrorResponse ( string $message, string $description = '', string $code = '' )
$message string Error message.
$description string Error description.
$code string Error code.
    public function setErrorResponse($message, $description = '', $code = '')
    {
        $this->outputArray['errorReport']['message'] = $message;
        if (!empty($description)) {
            $this->outputArray['errorReport']['description'] = $description;
        }
        if (!empty($code)) {
            $this->outputArray['errorReport']['code'] = $code;
        }
        return $this;
    }

Usage Example

示例#1
0
 public function testGetErrorTrue()
 {
     $cr = new CallbackResult();
     $cr->setErrorResponse('Error message', 'Error desc', '555');
     $cr->addErrorMessage(['ref' => 'testing']);
     $error = $cr->getError();
     $this->assertNotFalse($error);
     $this->assertSame('testing', $error['errors'][0]['ref']);
 }
All Usage Examples Of Webiny\Component\Rest\Response\CallbackResult::setErrorResponse