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

Export error types, improve error documentation for TypeScript #2367

Closed
fastfedora opened this issue Sep 21, 2020 · 1 comment · Fixed by #2561
Closed

Export error types, improve error documentation for TypeScript #2367

fastfedora opened this issue Sep 21, 2020 · 1 comment · Fixed by #2561
Assignees
Labels
type: feature request ‘Nice-to-have’ improvement, new feature or different behavior or design.

Comments

@fastfedora
Copy link

fastfedora commented Sep 21, 2020

When using the Calendar API, methods will throw an error, but there is no way to access the type of this error via TypeScript.

It appears this error is either a GaxiosError or RequestError from the form (properties include response, config, code, errors). However, the only error interface export from calendar_v3 is Schema$Error, which is an incomplete description of the actual API-specific error provided under the errors property of the error thrown.

I searched the entire TypeScript definition file and could not find any error interface exported by googleapis that could be used to properly type the error being thrown (in my specific case, from calendar_v3.Resource$Events.list).

It would be helpful if a GoogleApiError interface was defined that defined the specific shape of a Google API error, or, if that is not possible, API specific error types such as GoogleCalendarApiError.

At a minimum, it would be nice to at least re-export the GaxiosError, so the gaxios package does not have to be added as a dependency and kept in sync just to access this type. But since the implementation might change in the future away from Gaxios, it would be preferred to export a package-specific error that also includes the errors property added by at least the Calendar API calls:

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

Finally, it would also be helpful if some documentation was added on how to use these types. For instance, it took me over an hour to figure out that I could access the error schema for the Calendar via:

import { calendar_v3 } from 'googleapis';
import CalendarError = calendar_v3.Schema$Error;
@dandv
Copy link

dandv commented Sep 27, 2024

For those who land here from a web search, the type is Common.GaxiosError:

import { Common } from 'googleapis';
if (e instanceof Common.GaxiosError) ...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: feature request ‘Nice-to-have’ improvement, new feature or different behavior or design.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants