Transform ApiResponse::error() into dynamic method
This commit is contained in:
parent
ea0f41ecf0
commit
ebf56674f1
3 changed files with 5 additions and 5 deletions
|
@ -283,7 +283,7 @@ function api_call(App $a, App\Arguments $args = null)
|
||||||
Logger::warning(API_LOG_PREFIX . 'not implemented', ['module' => 'api', 'action' => 'call', 'query' => DI::args()->getQueryString()]);
|
Logger::warning(API_LOG_PREFIX . 'not implemented', ['module' => 'api', 'action' => 'call', 'query' => DI::args()->getQueryString()]);
|
||||||
throw new NotFoundException();
|
throw new NotFoundException();
|
||||||
} catch (HTTPException $e) {
|
} catch (HTTPException $e) {
|
||||||
ApiResponse::error($e->getCode(), $e->getDescription(), $e->getMessage(), $type);
|
DI::apiResponse()->error($e->getCode(), $e->getDescription(), $e->getMessage(), $type);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -135,17 +135,17 @@ class ApiResponse
|
||||||
*
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public static function error(int $code, string $description, string $message, string $format = null)
|
public function error(int $code, string $description, string $message, string $format = null)
|
||||||
{
|
{
|
||||||
$error = [
|
$error = [
|
||||||
'error' => $message ?: $description,
|
'error' => $message ?: $description,
|
||||||
'code' => $code . ' ' . $description,
|
'code' => $code . ' ' . $description,
|
||||||
'request' => DI::args()->getQueryString()
|
'request' => $this->args->getQueryString()
|
||||||
];
|
];
|
||||||
|
|
||||||
header(($_SERVER['SERVER_PROTOCOL'] ?? 'HTTP/1.1') . ' ' . $code . ' ' . $description);
|
header(($_SERVER['SERVER_PROTOCOL'] ?? 'HTTP/1.1') . ' ' . $code . ' ' . $description);
|
||||||
|
|
||||||
DI::apiResponse()->exit('status', ['status' => $error], $format);
|
$this->exit('status', ['status' => $error], $format);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -60,7 +60,7 @@ class Activity extends BaseApi
|
||||||
}
|
}
|
||||||
DI::apiResponse()->exit('ok', ['ok' => $ok], $parameters['extension'] ?? null);
|
DI::apiResponse()->exit('ok', ['ok' => $ok], $parameters['extension'] ?? null);
|
||||||
} else {
|
} else {
|
||||||
ApiResponse::error(500, 'Error adding activity', '', $parameters['extension'] ?? null);
|
DI::apiResponse()->error(500, 'Error adding activity', '', $parameters['extension'] ?? null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue