-
Notifications
You must be signed in to change notification settings - Fork 58
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add request and response interceptors (#619)
* feat: add request and response interceptors * pin compodoc due to unsupported node version in downstream dep * separate functions to apply request and response interceptors * Use map instead of array * update docs * use set instead of map
- Loading branch information
1 parent
1d31567
commit 059fe77
Showing
6 changed files
with
340 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
// Copyright 2024 Google LLC | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
import {GaxiosError, GaxiosOptions, GaxiosResponse} from './common'; | ||
|
||
/** | ||
* Interceptors that can be run for requests or responses. These interceptors run asynchronously. | ||
*/ | ||
export interface GaxiosInterceptor<T extends GaxiosOptions | GaxiosResponse> { | ||
/** | ||
* Function to be run when applying an interceptor. | ||
* | ||
* @param {T} configOrResponse The current configuration or response. | ||
* @returns {Promise<T>} Promise that resolves to the modified set of options or response. | ||
*/ | ||
resolved?: (configOrResponse: T) => Promise<T>; | ||
/** | ||
* Function to be run if the previous call to resolved throws / rejects or the request results in an invalid status | ||
* as determined by the call to validateStatus. | ||
* | ||
* @param {GaxiosError} err The error thrown from the previously called resolved function. | ||
*/ | ||
rejected?: (err: GaxiosError) => void; | ||
} | ||
|
||
/** | ||
* Class to manage collections of GaxiosInterceptors for both requests and responses. | ||
*/ | ||
export class GaxiosInterceptorManager< | ||
T extends GaxiosOptions | GaxiosResponse, | ||
> extends Set<GaxiosInterceptor<T> | null> {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.