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

Check MIME-Type before parsing body content #37

Open
BenjaminHofstetter opened this issue Apr 7, 2022 · 5 comments
Open

Check MIME-Type before parsing body content #37

BenjaminHofstetter opened this issue Apr 7, 2022 · 5 comments

Comments

@BenjaminHofstetter
Copy link

Problem:
checkResponse(res) is checking for HTTP Status Code 200 OK. This is not enough. Stardog is answering with Status Code OK on failure but the content is JSON with an Error description.

In the code ... https://github.com/zazuko/sparql-http-client/blob/b8575ba15260ff3f038326bc757c3bf9f6dff10b/StreamQuery.js#L56

we check checkResponse(res) for HTTP 200 and then the body is parsed with N3Parser.

    await checkResponse(res)

    const parser = new N3Parser({ factory: this.factory })

    return parser.import(res.body)

Because Stardog is sending HTTP 200 on error parser.import(res.body) tries to parse a JSON body. This leads to a parsing error.
To avoid this we should check if the content type is application/n-triples or text/turtle before parsing it.

@tpluscode
Copy link
Contributor

This should totally be fixed by Stardog too xd

@ktk
Copy link

ktk commented Jun 3, 2022

Not sure what the conclusion is so far. I think we can agree that 200 is not very helpful in this case, the question is should there be a way to have an override of an error-handler so we can catch particularities like what Stardog is doing?

@mielvds if I get you correctly you cannot get the JSON returned from Stardog at the moment? At least not in a parsable way

@mielvds
Copy link

mielvds commented Jun 7, 2022

The error I had turned out unrelated, so I removed the comments.

@ktk
Copy link

ktk commented Jun 7, 2022

@tpluscode do you have a proposal for what I should report @ Stardog?

@tpluscode
Copy link
Contributor

We already have, haven't we?

Regardless of this particular scenario, it is possible that the body is ini whatever way malformed and would fail to parse. Is it so that parser errors are not handled gracefully?

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

No branches or pull requests

4 participants