11import { APIGatewayEvent , Context , Callback } from 'aws-lambda' ;
2- import { Metrics , Body } from '../common' ;
2+ import { Metrics } from '../common' ;
3+ import { Body } from './body' ;
34
45const metrics = new Metrics ( 'API Gateway' ) ;
56
@@ -9,35 +10,35 @@ const HEADERS = {
910} ;
1011
1112export function apiWrapper < T extends Function > ( fn : T ) : T {
12- return < any > function ( event : APIGatewayEvent , context : Context , callback : Callback ) {
13+ return < any > function ( event : APIGatewayEvent ) {
1314 const { body, path, query, request, auth, headers, testRequest } = getRequestFields ( event ) ;
1415 metrics . common ( request ) ;
1516
16- function success ( payload : any = null ) : void {
17+ function success ( payload : any = null ) {
1718 const response = { statusCode : 200 , headers : HEADERS } ;
1819 if ( payload ) {
1920 response [ 'body' ] = JSON . stringify ( payload ) ;
2021 }
2122 metrics . success ( payload ) ;
22- return callback ( null , response ) ;
23+ return response ;
2324 }
2425
25- function invalid ( errors : string [ ] = [ ] ) : void {
26- const response = { statusCode : 400 , headers : HEADERS , body : JSON . stringify ( { errors, request } ) } ;
26+ function invalid ( errors : string [ ] = [ ] ) {
27+ const response = { statusCode : 400 , headers : HEADERS , body : JSON . stringify ( { errors, event } ) } ;
2728 metrics . invalid ( response ) ;
28- return callback ( null , response ) ;
29+ return response ;
2930 }
3031
31- function redirect ( url : string ) : void {
32+ function redirect ( url : string ) {
3233 HEADERS [ 'Location' ] = url ;
3334 const response = { statusCode : 302 , headers : HEADERS } ;
3435 metrics . redirect ( response ) ;
35- return callback ( null , response ) ;
36+ return response ;
3637 }
3738
38- function error ( error : any = '' ) : void {
39+ function error ( error : any = '' ) {
3940 metrics . error ( error ) ;
40- return callback ( error ) ;
41+ throw new Error ( error ) ;
4142 }
4243
4344 const signature : ApiSignature = {
0 commit comments