Skip to content
This repository was archived by the owner on Nov 20, 2025. It is now read-only.

fix: update return type to be string vs. number - #1165

Closed
sofisl wants to merge 2 commits into
masterfrom
fixBranchError
Closed

sofisl wants to merge 2 commits into
masterfrom
fixBranchError

Conversation

@sofisl

@sofisl sofisl commented Apr 23, 2021

Copy link
Copy Markdown
Contributor

Fixes #1092
GaxiosError returns code as a string, but this method in the auth library overwrites the code as a number. We're just updating it to return a string to be consistent.

@sofisl
sofisl requested a review from a team April 23, 2021 16:56
@google-cla google-cla Bot added the cla: yes This human has signed the Contributor License Agreement. label Apr 23, 2021
@sofisl
sofisl requested a review from chingor13 April 23, 2021 16:57
@codecov

codecov Bot commented Apr 23, 2021 •

Copy link
Copy Markdown

Codecov Report

Merging #1165 (fa1507d) into master (241063a) will not change coverage.
The diff coverage is 100.00%.

Impacted file tree graph

@@           Coverage Diff           @@
##           master    #1165   +/-   ##
=======================================
  Coverage   93.76%   93.76%           
=======================================
  Files          28       28           
  Lines        6267     6267           
  Branches      656      611   -45     
=======================================
  Hits         5876     5876           
  Misses        391      391           
Impacted Files Coverage Δ
src/transporters.ts 100.00% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 241063a...fa1507d. Read the comment docs.

@bcoe bcoe left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I'm a little worried about this one, because when I write error handling for libraries I tend to assume integer error codes, for instance I would expect RequestError.code to be 500 not "500".

I think the appropriate fix would perhaps be switching the type to allow string | number, we should then make sure that a number error code is not mistakenly turned into a string anywhere in the flow of the application.

A string error code like ENOTFOUND, should remain a string.

A numeric error code like 500, should remain a number.

From the time of initially being thrown during a request with gaxios, through to it being caught by a user.

@sofisl

sofisl commented Apr 29, 2021

Copy link
Copy Markdown
Contributor Author

@bcoe, just to clarify, you're not recommending changing any of the existing code, just adding number as a possible type here, right?

The problem is that there is functionality currently that attempts to turn the error into a string, but it gets overwritten by the places identified in this PR. I'm worried that if we change that functionality, we'll break other things that depend on the error code being a string when not being passed through transporter

@sofisl

sofisl commented May 5, 2021

Copy link
Copy Markdown
Contributor Author

After further discussion, we are going to close this for now but we will open an issue to change the type to accept either a string or number on the next major bump.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

cla: yes This human has signed the Contributor License Agreement.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

err.code type changes from 'string' to 'number'.

2 participants