/home/suroeste/public_html/payments.transportessuroeste.com/src/Utils
Edit: /home/suroeste/public_html/payments.transportessuroeste.com/src/Utils/JsonResponse.php (2169B)
true,
'message' => $message,
'data' => $data,
'meta' => [
'timestamp' => date('Y-m-d\TH:i:s.uP'),
'request_id' => $_SERVER['HTTP_X_REQUEST_ID'] ?? bin2hex(random_bytes(8))
]
], $code);
}
public static function error(string $message, int $code = 400, array $errors = []): void
{
$response = [
'success' => false,
'message' => $message,
'error' => [
'code' => $code,
'type' => self::getErrorType($code)
],
'meta' => [
'timestamp' => date('Y-m-d\TH:i:s.uP'),
'request_id' => $_SERVER['HTTP_X_REQUEST_ID'] ?? bin2hex(random_bytes(8))
]
];
if (!empty($errors)) {
$response['error']['details'] = $errors;
}
self::send($response, $code);
}
private static function getErrorType(int $code): string
{
return match($code) {
400 => 'bad_request',
401 => 'unauthorized',
403 => 'forbidden',
404 => 'not_found',
405 => 'method_not_allowed',
409 => 'conflict',
413 => 'payload_too_large',
415 => 'unsupported_media_type',
422 => 'validation_error',
429 => 'rate_limit_exceeded',
500 => 'internal_error',
503 => 'service_unavailable',
default => 'error'
};
}
}