Auto-commit 2026-04-29 16:31
This commit is contained in:
54
node_modules/twilio/lib/base/TwilioServiceException.js
generated
vendored
Normal file
54
node_modules/twilio/lib/base/TwilioServiceException.js
generated
vendored
Normal file
@@ -0,0 +1,54 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
class TwilioServiceException extends Error {
|
||||
constructor(response) {
|
||||
const isResponseBodyString = typeof response.body == "string";
|
||||
const body = isResponseBodyString
|
||||
? parseResponseBody(response.body)
|
||||
: response.body;
|
||||
// Initialize status first for the error message
|
||||
const status = body?.status || response.statusCode;
|
||||
super(`[HTTP ${status}] ${body?.title || "Failed to execute request"}`);
|
||||
// Set all required properties
|
||||
this.type = body?.type || "";
|
||||
this.title = body?.title || "Failed to execute request";
|
||||
this.status = status;
|
||||
this.code = body?.code || 0;
|
||||
// Set optional properties
|
||||
if (body?.detail) {
|
||||
this.detail = body.detail;
|
||||
}
|
||||
if (body?.instance) {
|
||||
this.instance = body.instance;
|
||||
}
|
||||
if (body?.errors) {
|
||||
this.errors = body.errors;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Check if a response body matches the RFC-9457 structure
|
||||
* @param body - The response body to check
|
||||
* @returns true if the body has the required RFC-9457 fields
|
||||
*/
|
||||
static isRFC9457Response(body) {
|
||||
if (!body || typeof body !== "object") {
|
||||
return false;
|
||||
}
|
||||
// Check for required fields according to the spec
|
||||
return (typeof body.type === "string" &&
|
||||
typeof body.title === "string" &&
|
||||
typeof body.status === "number" &&
|
||||
typeof body.code === "number");
|
||||
}
|
||||
}
|
||||
exports.default = TwilioServiceException;
|
||||
function parseResponseBody(response_body) {
|
||||
let body = null;
|
||||
try {
|
||||
body = JSON.parse(response_body);
|
||||
}
|
||||
catch (catchError) {
|
||||
body = null;
|
||||
}
|
||||
return body;
|
||||
}
|
||||
Reference in New Issue
Block a user