Files
meetletacbfree/classes/registration/registration_exception.php
T
mrxzamani be252e49e2 Address Moodle Marketplace review for mod_meetletacbfree 1.1.3.
Migrate legacy ajax/JS to external services and AMD, enable TLS verification, scope admin CSS with RTLCSS-safe rules, and fix README/lang/boilerplate gaps.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-09-20 12:41:47 +03:30

102 lines
3.0 KiB
PHP

<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Structured registration API / local client exception.
*
* @package mod_meetletacbfree
* @copyright 2026 MeetLet <info@meetlet.net>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace mod_meetletacbfree\registration;
defined('MOODLE_INTERNAL') || die();
/**
* Carries stable error.code from the platform envelope (or a local SDK code).
*/
class registration_exception extends \moodle_exception {
/** @var string */
protected $apicode;
/** @var string */
protected $apimessage;
/** @var array|null */
protected $details;
/** @var string|null */
protected $requestid;
public function __construct(string $code, string $message = '', ?array $details = null, ?string $requestid = null) {
$code = strtoupper(trim($code));
if ($code === '') {
$code = 'UNKNOWN';
}
$this->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',
'meetletacbfree',
'',
$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);
}
}