apicode = $code; $this->apimessage = trim($message) !== '' ? trim($message) : $code; $this->details = is_array($details) ? $details : null; $this->requestid = $requestid !== null && $requestid !== '' ? $requestid : null; parent::__construct( 'registration_api_error', 'meetletacbmarketplace', '', $this->apicode . ': ' . $this->apimessage ); } public function get_error_code(): string { return $this->apicode; } public function get_api_message(): string { return $this->apimessage; } public function get_details(): ?array { return $this->details; } public function get_request_id(): ?string { return $this->requestid; } /** * @return array{code:string,message:string,details:?array,request_id:?string,at:int} */ public function to_last_error(): array { return [ 'code' => $this->apicode, 'message' => $this->apimessage, 'details' => $this->details, 'request_id' => $this->requestid, 'at' => time(), ]; } public static function from_throwable(\Throwable $e): self { if ($e instanceof self) { return $e; } $msg = $e->getMessage(); if (preg_match('/^([A-Z][A-Z0-9_]+)\s*:\s*(.*)$/s', $msg, $m)) { return new self($m[1], $m[2]); } return new self('UNKNOWN', $msg); } }