Skip to content

Export error types, improve error documentation for TypeScript #2367

Closed
@fastfedora

Description

@fastfedora

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;

Metadata

Metadata

Labels

type: feature request‘Nice-to-have’ improvement, new feature or different behavior or design.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions