@kontent-ai/core-sdk
Version:
Core package with shared / common functionality for Kontent.ai SDKs
31 lines • 1.51 kB
JavaScript
import { isNotUndefined } from "./core.utils.js";
export function isKontent404Error(error) {
return isErrorOfType("invalidResponse", error) && error.status === 404;
}
export function getErrorMessage({ method, url, adapterResponse, kontentErrorResponse, }) {
const details = kontentErrorResponse ? getKontentErrorResponseMessage(adapterResponse, kontentErrorResponse) : undefined;
return `Failed to execute '${method}' request '${url}'.${details ? ` ${details}` : ""}`;
}
function isErrorOfType(reason, error) {
return error.reason === reason;
}
function getValidationErrorMessage(validationErrors) {
if (!validationErrors?.length) {
return undefined;
}
return validationErrors
.map((m) => {
const details = [
m.path ? `path: ${m.path}` : undefined,
m.line ? `line: ${m.line}` : undefined,
m.position ? `position: ${m.position}` : undefined,
].filter(isNotUndefined);
return `${m.message}${details.length ? ` (${details.join(", ")})` : ""}`;
})
.join(", ");
}
function getKontentErrorResponseMessage(adapterResponse, kontentErrorResponse) {
const validationErrorMessage = getValidationErrorMessage(kontentErrorResponse.validation_errors);
return `Response failed with status '${adapterResponse.status}' and status text '${adapterResponse.statusText}'.${kontentErrorResponse.message}${validationErrorMessage ? ` ${validationErrorMessage}` : ""}`;
}
//# sourceMappingURL=error.utils.js.map