@arizeai/phoenix-client
Version:
A client for the Phoenix API
37 lines • 1.29 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.isHttpError = isHttpError;
exports.isHttpErrorWithStatus = isHttpErrorWithStatus;
/**
* Type guard to check if an error is an HTTP error with a response status code.
* This safely narrows the type without unsafe type assertions.
*
* @param error - The error to check
* @returns True if the error has a response.status property
*/
function isHttpError(error) {
if (typeof error !== "object" || error === null) {
return false;
}
if (!("response" in error)) {
return false;
}
const errorWithResponse = error;
if (typeof errorWithResponse.response !== "object" ||
errorWithResponse.response === null) {
return false;
}
const response = errorWithResponse.response;
return "status" in response && typeof response.status === "number";
}
/**
* Safely checks if an error is an HTTP error with a specific status code.
*
* @param error - The error to check
* @param statusCode - The status code to check for
* @returns True if the error has the specified status code
*/
function isHttpErrorWithStatus(error, statusCode) {
return isHttpError(error) && error.response.status === statusCode;
}
//# sourceMappingURL=isHttpError.js.map