Skip to content

ApiException

Viames Marino edited this page Feb 23, 2026 · 1 revision

Pair framework: ApiException

Pair\Exceptions\ApiException is specialized for API request error handling.

Constructor behavior

__construct(string $message, int $code = 0, ?Throwable $previous = null):

  • logs error message (prefers previous exception message when available)
  • keeps API-oriented exception semantics from PairException hierarchy

Static reply helper

ApiException::reply(string $message, ?int $code = null, int $httpCode = 400): void

  • in production, replaces message with translated generic message
  • sends JSON error response

Implementation example

use Pair\Exceptions\ApiException;

if (!$token) {
    ApiException::reply('Missing token', 1001, 401);
}

See also: AjaxException, PairException, API.

Clone this wiki locally