Giter VIP home page Giter VIP logo

Comments (3)

ddelgrosso1 avatar ddelgrosso1 commented on June 26, 2024

Please see: #554 I believe this should resolve the issue you are facing with the missing text content handling.

from gaxios.

rotemdan avatar rotemdan commented on June 26, 2024

Thanks, I'll test it to ensure it works correctly in my case.

Looking at the code, I tried to find remaining potential places where the response is attempted to be parsed as JSON, in which gaxios would produce an error when the JSON fails to parse:

  • If the user doesn't specify a response type, getResponseDataFromContentType may throw an error if the server reports a content-type of application/json but the response fails to parse as JSON.
  • On the other hand, due to the try { ... } catch { /* continue */} in getResponseData, if the user explicitly requests a 'json' response type, and the parsing fails, they will not get an error, even if the server's returned content-type was actually application/json (the content-type is not checked in this case). That looks somewhat inconsistent, since I would assume that the expectation here would be stronger, since the both the user has explicitly indicated they expect a JSON response, and the server itself indicated that its content-type was supposed to be JSON (to clarify - I'm not necessarily suggesting having it error in this case is a good or bad idea, just mentioning this scenario for comparison).
  • I also noticed, in common.ts, that when constructing a GaxiosError, translateData may fail to parse the response as JSON in the cases where the user requested 'json', 'arraybuffer' or 'blob'. So it would fail to create a new GaxiosError object. Usually when constructing an Error object, it is undesirable to have the Error construction itself throw an Error. This isn't completely related to the original issue, but I noticed it.

from gaxios.

ddelgrosso1 avatar ddelgrosso1 commented on June 26, 2024

Regarding 1 & 2. I will put a fix in place to make it consistent behavior, thanks for the heads up! Let me take a closer look at 3.

from gaxios.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.