Skip to content

Commit cbc228a

Browse files
AllanZhengYPsrchase
authored andcommitted
Error Extractor (#91)
* add supports for service exception interface and error parser * generate new clients
1 parent 0be5b69 commit cbc228a

File tree

4 files changed

+46
-2
lines changed

4 files changed

+46
-2
lines changed

packages/types/src/exception.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import {ResponseMetadata} from './response';
2+
import { MetadataBearer } from './index';
3+
4+
/**
5+
* Exceptions that responded from AWS service containing raw http response
6+
* and parsed exception object
7+
*
8+
* @property {any} details - parsed exception object normalized according to
9+
* its API model
10+
*/
11+
export interface ServiceException<Details = any> extends Error, MetadataBearer {
12+
details: Details;
13+
}
14+
15+
/**
16+
* Service exceptions that can not be parsed by unmarshallers' error parser
17+
*/
18+
export interface UnkownServiceException extends ServiceException<undefined> {
19+
name: 'Error'
20+
}

packages/types/src/http.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,14 @@ export interface HttpResponse<StreamType = Uint8Array> extends
6767
statusCode: number;
6868
}
6969

70+
/**
71+
* Represents HTTP message whose body has been resolved to a string. This is
72+
* used in parsing http message.
73+
*/
74+
export interface ResolvedHttpResponse extends HttpResponse {
75+
body: string
76+
}
77+
7078

7179
/**
7280
* A class that stores httpOptions and can make requests by calling handle.

packages/types/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ export * from './client';
33
export * from './command';
44
export * from './credentials';
55
export * from './crypto';
6+
export * from './exception';
67
export * from './http';
78
export * from './logger';
89
export * from './marshaller';

packages/types/src/unmarshaller.ts

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
1-
import {Member, OperationModel} from "./protocol";
2-
import {HttpResponse} from "./http";
1+
import {
2+
Member,
3+
OperationModel,
4+
} from "./protocol";
5+
import {
6+
HttpResponse,
7+
ResolvedHttpResponse,
8+
} from "./http";
39
import {MetadataBearer} from './response';
10+
import {ServiceException} from './exception';
411

512
export interface BodyParser<SerializedType = string> {
613
/**
@@ -37,3 +44,11 @@ export interface ResponseParser<StreamType = Uint8Array> {
3744
export interface StreamCollector<StreamType> {
3845
(stream: StreamType): Promise<Uint8Array>;
3946
}
47+
48+
/**
49+
* A function that parses the http response when http status code > 299,
50+
* parse the error response according to response and throw the ServiceException
51+
*/
52+
export interface ServiceExceptionParser {
53+
(operation: OperationModel, response: ResolvedHttpResponse, errorBodyParser: BodyParser): ServiceException
54+
}

0 commit comments

Comments
 (0)