I am using google sdk to communicate with the admin api with TypeScript. Google sdk uses Gaxios to send requests. I would like to write error handling to methods from google api. I would like to check if the error is of the Gaxios error type, if so, I would throw the appropriate http error.
export const handleError = (error) => { ... // Handling errors from google sdk if(error instanceof GaxiosError){ return Handle(400, error.message) } return handle(500, "Unknown error"); }; The problem is that I can't write a class that will pass through instanceof, I don't want to install the entire Gaxios library to handle only google sdk errors.
This is my code:
export interface GaxiosResponse<T = any> { config: any; data: T; status: number; statusText: string; headers: any; request: any; } export interface GaxiosOptions {} export class GaxiosError<T = any> extends Error { code?: string; response?: GaxiosResponse<T>; config: GaxiosOptions; constructor(message: string, options: GaxiosOptions, response: GaxiosResponse<T>) { super(message); this.response = response; this.config = options; this.code = response.status.toString(); } } Related questions 10 Creating Google Map instance in typescript class 5 Typescript, google.maps.d.ts and type enforcement 142 Custom error class in TypeScript Related questions 10 Creating Google Map instance in typescript class 5 Typescript, google.maps.d.ts and type enforcement 142 Custom error class in TypeScript 6 Typescript Google API compilation errors 1 How to implement custom Error class in typescript? 5 How to display Typescript Runtime errors/exceptions in .ts instead of .js 10 How to define a Google Cloud Function with Typescript? 6 How to write an error handling decorator in typescript 3 Typescript: types for custom Error class as an argument 0 How to force a return type of Array onto typescript function Load 7 more related questions Show fewer related questions
Reset to default