Skip to content

Commit

Permalink
fix: #6067 - nodejs mock return error from lambda (#6096)
Browse files Browse the repository at this point in the history
  • Loading branch information
Attila Hajdrik committed Dec 11, 2020
1 parent b22e491 commit d6793c8
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ describe('VelocityTemplate', () => {
info,
);
expect(result.errors).toEqual([]);
expect(result.result).toEqual('some unexpected error, UnknowErrorType');
expect(result.result).toEqual('some unexpected error, UnknownErrorType');
});
});

Expand All @@ -88,7 +88,7 @@ describe('VelocityTemplate', () => {
info,
);
expect(result.errors).toEqual([]);
expect(result.result).toEqual('Error: my string as error, UnknowErrorType');
expect(result.result).toEqual('Error: my string as error, UnknownErrorType');
});
});

Expand Down
2 changes: 1 addition & 1 deletion packages/amplify-appsync-simulator/src/velocity/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ export class VelocityTemplate {
error: error
? {
...error,
type: error.extensions?.errorType || 'UnknowErrorType',
type: error.type || error.extensions?.errorType || 'UnknownErrorType',
message: error.message || `Error: ${error}`,
}
: error,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,16 +95,16 @@ process.on('message', async options => {
process.stdout.write('\n');
process.stdout.write(JSON.stringify({ result, error: null }));
} catch (error) {
process.send!(
process.stdout.write('\n');
process.stdout.write(
JSON.stringify({
result: null,
error: {
type: 'Lambda:Unhandled',
message: error.message,
message: error.message || typeof error === 'string' ? error : 'Unknown error', // In case of callback('error'), it is only a string
},
}),
);
exit(1);
}
exit(0);
});
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,9 @@ export function invoke(options: InvokeOptions): Promise<any> {
const result = JSON.parse(lastLine);
if (result.error) {
reject(result.error);
} else {
resolve(result.result);
}
resolve(result.result);
} catch {
resolve(lastLine);
}
Expand Down

0 comments on commit d6793c8

Please sign in to comment.