@loaders.gl/core
Version:
The core API for working with loaders.gl loaders and writers
26 lines (25 loc) • 869 B
JavaScript
// loaders.gl
// SPDX-License-Identifier: MIT
// Copyright (c) vis.gl contributors
// TODO - duplicates response-utils code
export function getErrorMessageFromResponseSync(response) {
return `Failed to fetch resource ${response.url}(${response.status}): ${response.statusText} `;
}
// TODO - duplicates response-utils code
export async function getErrorMessageFromResponse(response) {
let message = `Failed to fetch resource ${response.url} (${response.status}): `;
try {
const contentType = response.headers.get('Content-Type') || '';
if (contentType.includes('application/json')) {
message += await response.text();
}
else {
message += response.statusText;
}
}
catch (error) {
// eslint forbids return in finally statement
return message;
}
return message;
}