Skip to content

Commit

Permalink
fix: change the getSlotValue util function to return null when slot i…
Browse files Browse the repository at this point in the history
…s not present (#573)
  • Loading branch information
ShenChen93 committed Jul 16, 2019
1 parent 30e5560 commit 1321407
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 8 deletions.
7 changes: 2 additions & 5 deletions ask-sdk-core/lib/util/RequestEnvelopeUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ export function getSlot(requestEnvelope : RequestEnvelope, slotName : string) :
* Returns the value from the given {@link Slot} in the request.
*
* This method attempts to retrieve the requested {@link Slot}'s value from the incoming request. If the slot does not
* exist in the request, an Error will be raised.
* exist in the request, a null will be returned.
*
* @param {RequestEnvelope} requestEnvelope
* @param {string} slotName
Expand All @@ -188,10 +188,7 @@ export function getSlotValue(requestEnvelope : RequestEnvelope, slotName : strin
return slot.value;
}

throw createAskSdkError(
'RequestEnvelopeUtils',
`Cannot find slot with name ${slotName}.`,
);
return null;
}

throw createAskSdkError(
Expand Down
4 changes: 1 addition & 3 deletions ask-sdk-core/tst/util/RequestEnvelopeUtil.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,9 +151,7 @@ describe('RequestEnvelopeUtils', () => {
});

it('should throw an error if trying to get slot value of non existent slot', () => {
expect(() => {
getSlotValue(intentRequestEnvelope, 'non-existentSlot');
}).to.throw(`Cannot find slot with name non-existentSlot.`);
expect(getSlotValue(intentRequestEnvelope, 'non-existentSlot')).eq(null);
});

it('should throw an error if trying to get slot value of non-intent request', () => {
Expand Down

0 comments on commit 1321407

Please sign in to comment.