-
Notifications
You must be signed in to change notification settings - Fork 1
/
ReturnUnexpectedError.ts
38 lines (34 loc) · 1.13 KB
/
ReturnUnexpectedError.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import { AppSyncResolverEvent, Context } from 'aws-lambda';
import { Envelope } from '../core/Envelope';
import { UnexpectedError as _UnexpectedError } from '../core/AppError';
import { ExeResponse, IDecorator } from './IDecorator';
export class ReturnUnexpectedError<Request> implements IDecorator<Request> {
public wrapee: IDecorator<Request>['wrapee'];
public constructor(wrapee: IDecorator<Request>['wrapee']) {
this.wrapee = wrapee;
}
public async execute(
event: AppSyncResolverEvent<Request>,
context: Context
): ExeResponse {
console.log(`${this.constructor.name}.execute`);
try {
return await this.wrapee.execute(event, context);
} catch (error) {
console.log(
`An unexpected error occurred @ ${this.constructor.name}.execute`,
error
);
console.log(`Context`, event);
console.log(`Event`, context);
const r = {
...Envelope.error(new _UnexpectedError()),
logGroup: context.logGroupName,
logStream: context.logStreamName,
awsRequest: context.awsRequestId,
};
console.log(`return`, r);
return r;
}
}
}