Skip to content

Commit

Permalink
update example of throwOnHttpError
Browse files Browse the repository at this point in the history
  • Loading branch information
SofianD committed Feb 22, 2024
1 parent f85c20f commit 90abf84
Showing 1 changed file with 12 additions and 10 deletions.
22 changes: 12 additions & 10 deletions examples/throwOnHttpieError.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,20 @@ import * as httpie from "../dist/index.js";
// import * as httpie from "@myunisoft/httpie";

// Should not throw
async() => {
const { statusCode } = await httpie.request("GET", "127.0.0.1", { throwOnHttpError: false });
{
const { statusCode } = await httpie.request("GET", "127.0.0.1", {
throwOnHttpError: false
});

console.log(statusCode) // 500
}

// Should throw
async() => {
let statusCode;
try {
(statusCode = await httpie.request("GET", "127.0.0.1", { throwOnHttpError: true }));
} catch (error) {
console.log(statusCode) // undefined
console.log(error.statusCode) // 500
}
try {
await httpie.request("GET", "127.0.0.1", {
throwOnHttpError: true
});
}
catch (error) {
console.log(error.statusCode) // 500
}

0 comments on commit 90abf84

Please sign in to comment.