mirror of
https://github.com/hansjone/dsh-im-ops.git
synced 2026-10-09 00:33:20 +08:00
17 lines
660 B
JavaScript
17 lines
660 B
JavaScript
function text(value, maxLength) {
|
|
if (typeof value !== 'string') return null;
|
|
const trimmed = value.trim();
|
|
return trimmed ? trimmed.slice(0, maxLength) : null;
|
|
}
|
|
|
|
export function normalizeLastMessageError(value) {
|
|
if (!value || typeof value !== 'object' || Array.isArray(value)) return null;
|
|
const code = text(value.code, 64);
|
|
const reason = text(value.reason, 64);
|
|
const message = text(value.message, 500);
|
|
const referenceId = text(value.referenceId, 40);
|
|
const at = Number.isFinite(value.at) ? value.at : null;
|
|
return code && reason && message && referenceId && at !== null
|
|
? { code, reason, message, referenceId, at }
|
|
: null;
|
|
}
|