本文整理汇总了PHP中ApiError::message方法的典型用法代码示例。如果您正苦于以下问题:PHP ApiError::message方法的具体用法?PHP ApiError::message怎么用?PHP ApiError::message使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ApiError
的用法示例。
在下文中一共展示了ApiError::message方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: render
public function render()
{
$params = [];
$errorCode = ApiError::UNKNOWN;
if ($this->exception instanceof LackParametersException) {
$errorCode = ApiError::LACK_PARAMETERS;
$params['lackParameters'] = explode(', ', $this->exception->getMessage());
} elseif ($this->exception instanceof UnauthenticatedException) {
$errorCode = ApiError::UNAUTHENTICATED;
} elseif ($this->exception instanceof UnauthorizedException) {
$errorCode = ApiError::NOT_AUTHENTICATED;
}
$statusCode = $this->response->statusCode();
$errorMessages = ApiError::messages();
if (isset($errorMessages[$statusCode])) {
$errorCode = $statusCode;
}
if (Configure::read('debug') > 1 && $errorCode == ApiError::UNKNOWN) {
$params['debug'] = ['message' => $this->exception->getMessage(), 'trace' => explode("\n", $this->exception->getTraceAsString())];
}
$params = ['success' => false, 'code' => $statusCode, 'errorCode' => $errorCode, 'errorMessage' => ApiError::message($errorCode)] + $params;
$this->response->body(json_encode($params));
$this->response->type('json');
$this->response->send();
}
示例2: failure
/**
* レスポンスを失敗状態にします。
* エラーコード、HTTPステータスを指定できます。
*
* @param string $errorCode
* @param mixed $httpStatus
* @return void
* @see ApiError
*/
public function failure($errorCode, $httpStatus = 500)
{
$this->setResponse(['success' => false, 'code' => $httpStatus, 'errorCode' => $errorCode, 'errorMessage' => ApiError::message($errorCode)]);
}
示例3: failure
/**
* test failure() method
*
* @test
*/
public function failure()
{
$this->generateComponent();
$this->Api->failure(ApiError::VALIDATION_ERROR);
$this->assertSame(['success' => false, 'code' => 500, 'errorCode' => ApiError::VALIDATION_ERROR, 'errorMessage' => ApiError::message(ApiError::VALIDATION_ERROR)], $this->Api->getResponse());
$this->generateComponent();
$this->Api->failure(ApiError::VALIDATION_ERROR, 501);
$this->assertSame(501, $this->Api->getResponse()['code']);
}