Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: hide real error when user code throw error #1128

Merged
merged 4 commits into from
Jul 1, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion packages-serverless/serverless-fc-starter/src/runtime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -242,12 +242,26 @@ export class FCRuntime extends ServerlessLightRuntime {
// format context
const newCtx = {
logger: context.logger || console,
originEvent: event,
originContext: context,
};
// 其他事件场景
return this.invokeHandlerWrapper(newCtx, async () => {
args[0] = newCtx;
return handler.apply(handler, args);

try {
if (!handler) {
return await this.defaultInvokeHandler(...args);
} else {
return await handler.apply(handler, args);
}
} catch (err) {
if (isOutputError()) {
throw err;
} else {
throw new Error('Internal Server Error');
}
}
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ describe('/test/index.test.ts', () => {
}

assert.ok(err);
assert.equal(err.message, 'ooops!');
assert.equal(err.message, 'Internal Server Error');
});

it('should ok with asyncWrap when not async functions', async () => {
Expand Down
16 changes: 13 additions & 3 deletions packages-serverless/serverless-scf-starter/src/runtime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,15 +126,25 @@ export class SCFRuntime extends ServerlessLightRuntime {
// format context
const newCtx = {
logger: console,
originEvent: event,
originContext: context,
};
const args = [newCtx, event];
// 其他事件场景
return this.invokeHandlerWrapper(context, async () => {
if (!handler) {
return this.defaultInvokeHandler(...args);
try {
if (!handler) {
return this.defaultInvokeHandler(...args);
} else {
return handler.apply(handler, args);
}
} catch (err) {
if (isOutputError()) {
throw err;
} else {
throw new Error('Internal Server Error');
}
}
return handler.apply(handler, args);
});
}

Expand Down