Slide 43
Slide 43 text
class ApiController extends Controller
{
const CODE_WRONG_ARGS = 'GEN-1WT45PO';
const CODE_NOT_FOUND = 'GEN-LPF2FV6';
const CODE_INTERNAL_ERROR = 'GEN-A9AR4H';
const CODE_UNAUTHORIZED = 'GEN-M36UI';
const CODE_FORBIDDEN = ‘GEN-23T7';
protected function respondWithError($message, $errorCode)
{
return $this->respondWithArray([
'error' => [
'code' => $errorCode,
'http_code' => $this->statusCode,
'message' => $message,
]
]);
}
public function errorNotFound($message = 'Resource Not Found')
{
return $this->setStatusCode(404)->respondWithError($message,
self::CODE_NOT_FOUND);
}
public function errorUnauthorized($message = 'Unauthorized')
{
return $this->setStatusCode(401)->respondWithError($message,
self::CODE_UNAUTHORIZED);
}
//errorForbidden, errorInternalError, …