across-bridge-v3-sdk
Version:
Light-weighted SDK for interacting with Across V3 API
32 lines • 1.15 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.get = get;
const node_fetch_1 = __importDefault(require("node-fetch"));
// eslint-disable-next-line @typescript-eslint/no-explicit-any
async function get(url) {
try {
if (!url) {
throw new Error('URL is required');
}
const response = await (0, node_fetch_1.default)(url);
const data = await response.json();
if (!response.ok) {
throw new Error(`\nHTTP error: ${JSON.stringify(data, null, 2)}`);
}
const contentType = response.headers.get('content-type');
if (!contentType || !contentType.includes('application/json')) {
throw new Error('Response is not JSON');
}
return data;
}
catch (error) {
if (error instanceof Error) {
throw new Error(`Failed to fetch: ${error.message}`);
}
throw new Error('An unknown error occurred');
}
}
//# sourceMappingURL=http.js.map