lambder 1.0.54 → 1.0.55
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/Lambder.js +19 -20
- package/package.json +1 -1
- package/src/Lambder.ts +16 -16
package/dist/Lambder.js
CHANGED
|
@@ -199,30 +199,29 @@ export default class Lambder {
|
|
|
199
199
|
let ctx = createContext(event, lambdaContext);
|
|
200
200
|
eventRenderContext = ctx;
|
|
201
201
|
return await new Promise(async (resolve, reject) => {
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
202
|
+
try {
|
|
203
|
+
const resolver = this.getResolver(resolve, reject);
|
|
204
|
+
if (ctx.method === "OPTIONS")
|
|
205
|
+
return resolver.cors();
|
|
206
|
+
const firstMatchedAction = this.actionList.find(action => action.conditionFn(ctx));
|
|
207
|
+
if (firstMatchedAction) {
|
|
208
|
+
for (const hook of this.hookList["beforeRender"]) {
|
|
209
|
+
ctx = await hook.hookFn(ctx, resolver);
|
|
210
|
+
}
|
|
211
|
+
let response = await firstMatchedAction.actionFn(ctx, resolver);
|
|
212
|
+
for (const hook of this.hookList["afterRender"]) {
|
|
213
|
+
response = await hook.hookFn(ctx, resolver, response);
|
|
214
|
+
}
|
|
215
|
+
resolve(response);
|
|
209
216
|
}
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
response = await hook.hookFn(ctx, resolver, response);
|
|
217
|
+
else {
|
|
218
|
+
return this.handleNoMatchedAction(ctx, resolver);
|
|
213
219
|
}
|
|
214
|
-
resolve(response);
|
|
215
220
|
}
|
|
216
|
-
|
|
217
|
-
|
|
221
|
+
catch (err) {
|
|
222
|
+
const wrappedError = err instanceof Error ? err : new Error("Error: " + String(err));
|
|
223
|
+
reject(wrappedError);
|
|
218
224
|
}
|
|
219
|
-
}).then(async (response) => {
|
|
220
|
-
for (const hook of this.hookList["completed"]) {
|
|
221
|
-
response = await hook.hookFn(response);
|
|
222
|
-
}
|
|
223
|
-
return response;
|
|
224
|
-
}).catch((reason) => {
|
|
225
|
-
throw reason;
|
|
226
225
|
});
|
|
227
226
|
}
|
|
228
227
|
catch (err) {
|
package/package.json
CHANGED
package/src/Lambder.ts
CHANGED
|
@@ -280,23 +280,23 @@ export default class Lambder {
|
|
|
280
280
|
resolve:(response: ResolverResponse)=>void,
|
|
281
281
|
reject:(err: Error)=>void
|
|
282
282
|
)=> {
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
283
|
+
try{
|
|
284
|
+
const resolver = this.getResolver(resolve, reject);
|
|
285
|
+
if(ctx.method === "OPTIONS") return resolver.cors();
|
|
286
|
+
|
|
287
|
+
const firstMatchedAction = this.actionList.find(action => action.conditionFn(ctx));
|
|
288
|
+
if(firstMatchedAction){
|
|
289
|
+
for(const hook of this.hookList["beforeRender"]){ ctx = await hook.hookFn(ctx, resolver); }
|
|
290
|
+
let response = await firstMatchedAction.actionFn(ctx, resolver);
|
|
291
|
+
for(const hook of this.hookList["afterRender"]){ response = await hook.hookFn(ctx, resolver, response); }
|
|
292
|
+
resolve(response);
|
|
293
|
+
}else{
|
|
294
|
+
return this.handleNoMatchedAction(ctx, resolver);
|
|
295
|
+
}
|
|
296
|
+
} catch(err){
|
|
297
|
+
const wrappedError = err instanceof Error ? err : new Error("Error: " + String(err));
|
|
298
|
+
reject(wrappedError);
|
|
294
299
|
}
|
|
295
|
-
}).then(async (response: ResolverResponse):Promise<ResolverResponse> => {
|
|
296
|
-
for(const hook of this.hookList["completed"]){ response = await hook.hookFn(response); }
|
|
297
|
-
return response;
|
|
298
|
-
}).catch((reason: Error)=>{
|
|
299
|
-
throw reason;
|
|
300
300
|
})
|
|
301
301
|
}catch(err){
|
|
302
302
|
if(this.globalErrorHandler){
|