Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: improve error handling and parser #224

Closed
wants to merge 0 commits into from

Conversation

SofianD
Copy link
Contributor

@SofianD SofianD commented Jan 26, 2024

No description provided.

@SofianD SofianD force-pushed the fix-parseUndiciResponse branch from ba70dc2 to 37d7cc5 Compare January 26, 2024 15:42
test/utils.spec.ts Outdated Show resolved Hide resolved
@SofianD SofianD self-assigned this Jan 26, 2024
@SofianD SofianD marked this pull request as draft January 26, 2024 16:03
test/utils.spec.ts Outdated Show resolved Hide resolved
src/request.ts Outdated Show resolved Hide resolved
@SofianD SofianD force-pushed the fix-parseUndiciResponse branch 2 times, most recently from 4e4d3cf to 0bc42c9 Compare February 5, 2024 13:57
@SofianD SofianD marked this pull request as ready for review February 5, 2024 13:59
@SofianD SofianD force-pushed the fix-parseUndiciResponse branch 2 times, most recently from 9d8cc24 to 3791587 Compare February 5, 2024 14:38
@SofianD SofianD changed the title fix(utils.ts): parseUndiciResponse handles application/pdf header, it now returns the buffer without converting it to a string feat: improve error handling and parser Feb 5, 2024
src/common/errors.ts Outdated Show resolved Hide resolved
src/common/errors.ts Outdated Show resolved Hide resolved
src/common/errors.ts Outdated Show resolved Hide resolved
src/common/errors.ts Outdated Show resolved Hide resolved
src/request.ts Outdated Show resolved Hide resolved
src/request.ts Outdated
Comment on lines 90 to 98
if (options.mode === "parse" || !options.mode) {
data = await responseHandler.getData<T>("parse");
}
else if (options.mode === "decompress") {
data = await responseHandler.getData("decompress");
}
else {
data = await responseHandler.getData("raw");
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (options.mode === "parse" || !options.mode) {
data = await responseHandler.getData<T>("parse");
}
else if (options.mode === "decompress") {
data = await responseHandler.getData("decompress");
}
else {
data = await responseHandler.getData("raw");
}
if (options.mode === "parse" || !options.mode) {
data = await responseHandler.getData<T>("parse");
}
else {
data = await responseHandler.getData(options.mode);
}

Copy link
Member

@fraxken fraxken left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you need to update the README to includes new docs like errors no?

Comment on lines 6 to 7
// Import Third-party Dependencies
import { brotliCompressSync, deflateSync, gzipSync } from "zlib";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

zlib is a Node dependency

test/undiciResponseHandler.spec.ts Outdated Show resolved Hide resolved
src/utils.ts Outdated
@@ -83,6 +47,14 @@ export function createHeaders(options: Partial<Pick<RequestOptions, "headers" |
return headers;
}

export function isHttpieError(error) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
export function isHttpieError(error) {
export function isHttpieError(error: unknown): error is HttpieError {

src/utils.ts Outdated
return error instanceof HttpieError;
}

export function isHTTPError(error) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
export function isHTTPError(error) {
export function isHTTPError(error: unknown): error is HttpieOnHttpError {

Comment on lines 1 to 17
// Import Internal Dependencies
import { HttpieOnHttpError } from "../src/class/HttpieOnHttpError";

describe("HttpieOnHttpError", () => {
it("it should create an HttpieOnHttpError with the properties of RequestResponse", () => {
const reqResponse = {
statusCode: 404,
statusMessage: "Not Found",
data: null,
headers: {}
};

const error = new HttpieOnHttpError(reqResponse);
expect(error.name).toStrictEqual("HttpieOnHttpError");
expect(error).toMatchObject(reqResponse);
});
});
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test do not provide any value (not testing anything).

@SofianD SofianD closed this Feb 8, 2024
@SofianD SofianD force-pushed the fix-parseUndiciResponse branch from 231d1c1 to 514bbd3 Compare February 8, 2024 14:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants