digitCode = $digitCode; $this->digitMessage = $message; $this->httpStatus = $httpStatus; $this->responseBody = $responseBody; $this->requestUrl = $requestUrl; $this->requestBody = $requestBody; } public function getDigitCode() { return $this->digitCode; } public function getHttpStatus(): int { return $this->httpStatus; } public function getResponseBody() { return $this->responseBody; } public function getRequestUrl(): ?string { return $this->requestUrl; } public function getRequestBody() { return $this->requestBody; } public function isInfraError(): bool { $code = (string) $this->digitCode; return in_array($code, ['403', '999'], true) || in_array($this->httpStatus, [403], true); } /** * Compact log line with url / request / response for debugging. */ public function toLogMessage(): string { $encode = static function ($value): string { if ($value === null) { return 'null'; } if (is_string($value)) { return $value; } $json = json_encode($value, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE); return $json !== false ? $json : '[unencodable]'; }; return 'DigitMotor API error: ' . $this->getMessage() . ' | code=' . $this->digitCode . ' | http=' . $this->httpStatus . ' | url=' . ($this->requestUrl ?? 'n/a') . ' | request=' . $encode($this->requestBody) . ' | response=' . $encode($this->responseBody); } }