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

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

Closed
scschl opened this issue Oct 26, 2020 · 5 comments · Fixed by googleapis/gaxios#552
Closed

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

scschl opened this issue Oct 26, 2020 · 5 comments · Fixed by googleapis/gaxios#552
Assignees
Labels
priority: p2 Moderately-important priority. Fix may not be included in next release. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns.

Comments

@scschl
Copy link

scschl commented Oct 26, 2020

Thanks for stopping by to let us know something could be better!

PLEASE READ: If you have a support contract with Google, please create an issue in the support console instead of filing on GitHub. This will ensure a timely response.

  1. Is this a client library issue or a product issue?
    This is the client library for . We will only be able to assist with issues that pertain to the behaviors of this library. If the issue you're experiencing is due to the behavior of the product itself, please visit the Support page to reach the most relevant engineers.

  2. Did someone already solve this?

  1. Do you have a support contract?
    Please create an issue in the support console to ensure a timely response.

If the support paths suggested above still do not result in a resolution, please provide the following details.

Environment details

  • OS: Windows 10.0.18362
  • Node.js version: 12.13.0
  • npm version: 6.12.0
  • google-auth-library version: 6.1.1.

Steps to reproduce

  1. Call google.classroom("v1").courses.list(), or any related API (courses.teacher, courses.student, etc.)
  2. Keep calling until a quota threshold is reached (should get a 429 error code).
  3. Look at the typeof the error.code returned. It will be a 'number', but should be a 'string'.

Looks like
err.code = body.error.code;
around line 95 in processError() in transporters.js needs to ensure the assigned value is a string.

Line 112 handles this by calling toString(). Might be other lines that need to ensure the code field is a string type.

Making sure to follow these steps will guarantee the quickest resolution possible.

Thanks!

@yoshi-automation yoshi-automation added the triage me I really want to be triaged. label Oct 27, 2020
@bcoe bcoe added type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns. priority: p2 Moderately-important priority. Fix may not be included in next release. labels Oct 27, 2020
@bcoe
Copy link
Contributor

bcoe commented Oct 27, 2020

@scschl I would expect error.code to be a number, is the problem that the types indicate that it's a string?

@yoshi-automation yoshi-automation removed the triage me I really want to be triaged. label Oct 27, 2020
@scschl
Copy link
Author

scschl commented Oct 28, 2020

Yes, it seems inconsistent that sometimes 'code' is a string and other times it's a 'number'. The types indicate it should be a string:
I'm assuming that the error returned is of type RequestError (correct me if that's wrong):

export interface RequestError extends GaxiosError {
errors: Error[];
}

export declare class GaxiosError<T = any> extends Error {
code?: string;
response?: GaxiosResponse;
config: GaxiosOptions;
constructor(message: string, options: GaxiosOptions, response: GaxiosResponse);
}

@scschl
Copy link
Author

scschl commented Oct 28, 2020

Also, if it's expected to be a number, why is it explicitly converted to a string if the status is >=400 ?

else if (res && res.status >= 400) {
// Consider all 4xx and 5xx responses errors.
err.message = body;
err.code = res.status.toString();

@yoshi-automation yoshi-automation added 🚨 This issue needs some love. and removed 🚨 This issue needs some love. labels Jan 26, 2021
@sofisl
Copy link
Contributor

sofisl commented Apr 23, 2021

Hi there, thanks for submitting this bug! I can confirm that this is happening. Since GaxiosError expects code to be a string, it seems like this is indeed a bug.

I've addressed it in #1165.

@sofisl sofisl closed this as completed Apr 23, 2021
@sofisl sofisl assigned sofisl and unassigned bcoe Apr 23, 2021
@bcoe
Copy link
Contributor

bcoe commented May 4, 2021

@scschl we intend to address this issue, but all the fixes we could think of would be a breaking change for many of our libraries.

Are you able to workaround the issue today by running Number(err.code), and in the next major release for our libraries we will sort out these conversion issues?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
priority: p2 Moderately-important priority. Fix may not be included in next release. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns.
Projects
None yet
4 participants