All errors generated by Httpie failure inherit HttpieError.
interface HttpieError {
headers: IncomingHttpHeaders;
statusCode: number;
}The isHttpieError function can be used to find out weither the error is a @openally/httpie or a undici error.
function isHttpieError(error: unknown): boolean;Example:
import * as httpie from "@openally/httpie";
try {
await httpie.request("GET", "127.0.0.1");
}
catch (error) {
if (httpie.isHttpieError(error)) {
// This error inherits from HttpieError.
console.log(Boolean(error.headers)) // true
console.log(Boolean(error.statusCode)) // true
}
else {
// This error can be of any error type.
console.log(Boolean(error.headers)) // false
console.log(Boolean(error.statusCode)) // false
}
}The isHTTPError function can be used to find out if it is an HTTP error.
function isHTTPError(error: unknown): boolean;Example:
import * as httpie from "@openally/httpie";
try {
await httpie.request("GET", "127.0.0.1");
}
catch (error) {
if (httpie.isHTTPError(error)) {
console.log(Boolean(error.data)) // true
console.log(Boolean(error.statusMessage)) // true
console.log(Boolean(error.headers)) // true
console.log(Boolean(error.statusCode)) // true
}
else {
// This error can be of any error type.
console.log(Boolean(error.data)) // false
console.log(Boolean(error.statusMessage)) // false
}
}If the RequestOptions.throwOnHttpError option is set to true, all HTTP responses with a status code higher than 400 will generate an HttpieOnHttpError error.
Note
Use isHTTPError function to know if it is an HTTP error.
interface HttpieOnHttpError<T> {
statusCode: number;
statusMessage: string;
headers: IncomingHttpHeaders;
data: T;
}interface HttpieFetchBodyError {
statusCode: number;
headers: IncomingHttpHeaders;
message: string;
/** @description original error */
error?: Error;
}If the RequestOptions.mode option is set with decompress or parse, Httpie will try to decompress the response body based on the content-encoding header.
If Httpie fails to decompress the response body, an HttpieDecompressionError will be raised.
interface HttpieDecompressionError {
statusCode: number;
headers: IncomingHttpHeaders;
message: string;
/** @description original error */
error?: Error;
/** @description original body as buffer */
buffer: Buffer;
/** @description encodings from 'content-encoding' header */
encodings: string[];
}If the RequestOptions.mode option is set with parse, Httpie will try to parse the response body based on the content-type header.
If Httpie fails to parse the response body, an HttpieParserError will be raised.
interface HttpieParserError extends IHttpieHandlerError {
statusCode: number;
headers: IncomingHttpHeaders;
message: string;
/** @description original error */
error?: Error;
/** @description content-type from 'content-type' header without params */
contentType: string;
/** @description original body as buffer */
buffer: Buffer;
/** @description body as string */
text: string | null;
}