Add another check to the function caller to avoid exceptions (#5296)
This commit is contained in:
parent
2282963c97
commit
3a91d05835
2 changed files with 9 additions and 1 deletions
|
|
@ -12,7 +12,8 @@ class FunctionCaller
|
|||
def call
|
||||
response = aws_lambda_client.invoke(function_name: function_name, payload: payload)
|
||||
payload_json = response.payload.as_json[0]
|
||||
payload_json ? JSON.parse(JSON.parse(payload_json)["body"])["message"] : nil
|
||||
body = payload_json ? JSON.parse(payload_json)["body"] : nil
|
||||
body ? JSON.parse(body)["message"] : nil
|
||||
end
|
||||
|
||||
private
|
||||
|
|
|
|||
|
|
@ -26,4 +26,11 @@ RSpec.describe FunctionCaller, type: :labor do
|
|||
allow(empty_client).to receive(:invoke).and_return(empty_result)
|
||||
expect(described_class.call("some_function", payload, empty_client)).to be_nil
|
||||
end
|
||||
|
||||
it "doesn't fail when payload is empty and is a hash" do
|
||||
empty_result = result_struct.new(payload: [{}.to_json])
|
||||
empty_client = double
|
||||
allow(empty_client).to receive(:invoke).and_return(empty_result)
|
||||
expect(described_class.call("some_function", payload, empty_client)).to be_nil
|
||||
end
|
||||
end
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue