-
Notifications
You must be signed in to change notification settings - Fork 221
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- adds intermediat error type for typescript
- adds error mapping abstractions and implements deserialization of errors for typescript http Signed-off-by: Vincent Biret <vibiret@microsoft.com>
- Loading branch information
Showing
7 changed files
with
82 additions
and
44 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
/** Parent interface for errors thrown by the client when receiving failed responses to its requests. */ | ||
interface ApiError extends Error { | ||
} | ||
|
||
interface ApiErrorConstructor extends ErrorConstructor { | ||
new(message?: string): ApiError; | ||
(message?: string): ApiError; | ||
readonly prototype: ApiError; | ||
} | ||
|
||
export var ApiError: ApiErrorConstructor; |
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 |
---|---|---|
@@ -1,11 +1,15 @@ | ||
import { ResponseHandler } from "./responseHandler"; | ||
import { Parsable } from "./serialization"; | ||
|
||
/** Default response handler to access the native response object. */ | ||
export class NativeResponseHandler implements ResponseHandler { | ||
/** Native response object as returned by the core service */ | ||
public value?: any; | ||
public handleResponseAsync<NativeResponseType, ModelType>(response: NativeResponseType): Promise<ModelType> { | ||
/** The error mappings for the response to use when deserializing failed responses bodies. Where an error code like 401 applies specifically to that status code, a class code like 4XX applies to all status codes within the range if an the specific error code is not present. */ | ||
public errorMappings: Record<string, new () => Parsable> | undefined | ||
public handleResponseAsync<NativeResponseType, ModelType>(response: NativeResponseType, errorMappings: Record<string, new () => Parsable> | undefined): Promise<ModelType> { | ||
this.value = response; | ||
this.errorMappings = errorMappings; | ||
return Promise.resolve<ModelType>(undefined as any); | ||
} | ||
} |
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 |
---|---|---|
@@ -1,11 +1,14 @@ | ||
import { Parsable } from "./serialization"; | ||
|
||
/** Defines the contract for a response handler. */ | ||
export interface ResponseHandler { | ||
/** | ||
* Callback method that is invoked when a response is received. | ||
* @param response The native response object. | ||
* @param errorMappings the error factories mapping to use in case of a failed request. | ||
* @typeParam NativeResponseType The type of the native response object. | ||
* @typeParam ModelType The type of the response model object. | ||
* @return A {@link Promise} that represents the asynchronous operation and contains the deserialized response. | ||
*/ | ||
handleResponseAsync<NativeResponseType, ModelType>(response: NativeResponseType): Promise<ModelType>; | ||
handleResponseAsync<NativeResponseType, ModelType>(response: NativeResponseType, errorMappings: Record<string, new () => Parsable> | undefined): Promise<ModelType>; | ||
} |
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.