Skip to content
This repository has been archived by the owner on Nov 19, 2019. It is now read-only.

TwilioRestException: Script-thrown exception #56

Open
cconroy222 opened this issue Jan 10, 2016 · 11 comments
Open

TwilioRestException: Script-thrown exception #56

cconroy222 opened this issue Jan 10, 2016 · 11 comments

Comments

@cconroy222
Copy link

Installed the package into production and sandbox, tried migrating other code into production but had the following test failures:

Class Twilio_TestApplication
Method Name testTwilioAplications_filter
Pass/Fail Fail
Error Message TwilioRestException: Script-thrown exception
Stack Trace Class.TwilioRestClient: line 591, column 1
Class.TwilioResource: line 82, column 1
Class.TwilioResource.ListResource: line 463, column 1
Class.TwilioApplicationList: line 80, column 1
Class.Twilio_TestApplication.testTwilioAplications_filter: line 145, column 1

Class Twilio_TestApplication
Method Name testTwilioAplications_get
Pass/Fail Fail
Error Message TwilioRestException: Script-thrown exception
Stack Trace Class.TwilioRestClient: line 591, column 1
Class.TwilioResource: line 82, column 1
Class.TwilioResource.ListResource: line 463, column 1
Class.TwilioApplicationList: line 80, column 1
Class.Twilio_TestApplication.testTwilioAplications_get: line 66, column 1

Class Twilio_TestPhoneNumbers
Method Name testTwilioAvailablePhoneNumbers_AreaCodeFilter
Pass/Fail Fail
Error Message TwilioRestException: Script-thrown exception
Stack Trace Class.TwilioRestClient: line 591, column 1
Class.TwilioResource: line 82, column 1
Class.TwilioResource.ListResource: line 463, column 1
Class.TwilioAvailablePhoneNumberList: line 106, column 1
Class.Twilio_TestPhoneNumbers.testTwilioAvailablePhoneNumbers_AreaCodeFilter: line 274, column 1

@hhai
Copy link
Contributor

hhai commented Jan 10, 2016

Can you send along the Debug Log when you execute the tests?

Thanks,
Henry

Henry Hai
twilio cloud communications
Expert Services
e: [email protected]
m: (718) 757-7157

On Sat, Jan 9, 2016 at 7:46 PM, cconroy222 [email protected] wrote:

Installed the package into production and sandbox, tried migrating other
code into production but had the following test failures:

Class Twilio_TestApplication
Method Name testTwilioAplications_filter
Pass/Fail Fail
Error Message TwilioRestException: Script-thrown exception
Stack Trace ClassTwilioRestClient: line 591, column 1
ClassTwilioResource: line 82, column 1
ClassTwilioResourceListResource: line 463, column 1
ClassTwilioApplicationList: line 80, column 1
ClassTwilio_TestApplicationtestTwilioAplications_filter: line 145, column 1

Class Twilio_TestApplication
Method Name testTwilioAplications_get
Pass/Fail Fail
Error Message TwilioRestException: Script-thrown exception
Stack Trace ClassTwilioRestClient: line 591, column 1
ClassTwilioResource: line 82, column 1
ClassTwilioResourceListResource: line 463, column 1
ClassTwilioApplicationList: line 80, column 1
ClassTwilio_TestApplicationtestTwilioAplications_get: line 66, column 1

Class Twilio_TestPhoneNumbers
Method Name testTwilioAvailablePhoneNumbers_AreaCodeFilter
Pass/Fail Fail
Error Message TwilioRestException: Script-thrown exception
Stack Trace ClassTwilioRestClient: line 591, column 1
ClassTwilioResource: line 82, column 1
ClassTwilioResourceListResource: line 463, column 1
ClassTwilioAvailablePhoneNumberList: line 106, column 1
ClassTwilio_TestPhoneNumberstestTwilioAvailablePhoneNumbers_AreaCodeFilter:
line 274, column 1


Reply to this email directly or view it on GitHub
#56.

@cconroy222
Copy link
Author

@hhai
Copy link
Contributor

hhai commented Jan 15, 2016

This was a salesforce enhancement "*Predictable Iteration Order for
Unordered Collections” *
https://help.salesforce.com/apex/HTViewSolution?id=000213516&language=en_US

that caused issues with the test classes and the order of the URL
parameters which the test harness expected.
https://api.twilio.com/2010-04-01/Accounts/AC03c2fcd60e144e7cbeee413fcbf812a3/Applications.json?FriendlyName=Testapp1&VoiceMethod=POST
TestApplication
15:09:18.124
(1124927360)|USER_DEBUG|[77]|DEBUG|Twilio_TestHTTPMock::getResponse() Did
not find Resource for GET
https://api.twilio.com/2010-04-01/Accounts/AC03c2fcd60e144e7cbeee413fcbf812a3/Applications.json?FriendlyName=Testapp1&VoiceMethod=POST

Expected Order from the test request.
<Twilio_TestApplication.cls>
map<string,string> params=new map<string,string>();
params.put('VoiceMethod','POST');
params.put('FriendlyName','Testapp1');

TestPhoneNumber
15:09:18.217
(1217607174)|USER_DEBUG|[77]|DEBUG|Twilio_TestHTTPMock::getResponse() Did
not find Resource for GET
https://api.twilio.com/2010-04-01/Accounts/ACba8bc05eacf94afdae398e642c9cc32d/AvailablePhoneNumbers/US/Local.json?Contains=51034*****&AreaCode=510

Expected Order form the test request.
<Twilio_TestPhoneNumbers.cls>
map<string,string> params=new map<string,string>();
params.put('AreaCode','510');
params.put('Contains','51034*****');

You could either update the URL parameters to match the MAP or vice versa.

@cconroy222
Copy link
Author

Switched the order of the puts for the map and the same issue persists.

Twilio_testApplication log.txt

@cconroy222
Copy link
Author

Also tried changing the order of the URL params and that didn't fix anything either.

@hhai
Copy link
Contributor

hhai commented Jan 18, 2016

From the debug log it still seems that it cannot match the URL strings
properly, and the parameters are still in the wrong order. Can you confirm
that you updated the params to look like this.

map<string,string> params=new map<string,string>();
params.put('VoiceMethod','POST');
params.put('FriendlyName','Testapp1');
// Get an API client and request
the Twilio Account TwilioRestClient client = new
TwilioRestClient('AC03c2fcd60e144e7cbeee413fcbf812a3', authToken);
TwilioApplicationList twapps = client.getAccount().getApplications(params);

15:47:41.131 (1131101871)|USER_DEBUG|[73]|DEBUG|Resource Map:{
HTTPS://API.TWILIO.COM/2010-04-01/ACCOUNTS/AC03C2FCD60E144E7CBEEE413FCBF812A3/APPLICATIONS.JSON?VOICEMETHOD=POST&FRIENDLYNAME=TESTAPP1=Response:[body={"applications":[{"sid":"AP023e78c7f13a4fe683ef2e5ddc510399","date_created":"Wed,
01 Feb 2012 10:49:17 +0000","date_updated":"Wed, 01 Feb 2012 10:49:17
+0000","account_sid":"AC03c2fcd60e144e7cbeee413fcbf812a3","friendly_name":"Testapp1","api_version":"2010-04-01","voice_url":null,"voice_method":"POST","voice_fallback_url":null,"voice_fallback_method":"POST","status_callback":null,"status_callback_method":"POST","voice_caller_id_lookup":false,"sms_url":null,"sms_method":"POST","sms_fallback_url":null,"sms_fallback_method":"POST","sms_status_callback":null,"uri":"/2010-04-01/Accounts/AC03c2fcd60e144e7cbeed179fcbf812a3/Applications/AP023e78c7f13a4fe683ef2e5ddc510399.json"}],"page":0,"num_pages":1,"page_size":50,"total":1,"start":0,"end":0,"uri":"/2010-04-01/Accounts/AC03c2fcd60e144e7cbeed179fcbf812a3/Applications.json?VoiceMethod=POST&FriendlyName=Testapp1","first_page_uri":"/2010-04-01/Accounts/AC03c2fcd60e144e7cbeed179fcbf812a3/Applications.json?VoiceMethod=POST&FriendlyName=Testapp1&Page=0&PageSize=50","previous_page_uri":null,"next_page_uri":null,"last_page_uri":"/2010-04-01/Accounts/AC03c2fcd60e144e7cbeed179fcbf812a3/Applications.json?VoiceMethod=POST&FriendlyName=Testapp1&Page=0&PageSize=50"},
headers={Content-Type=application/json}, statusCode=200]} , Keys :{
HTTPS://API.TWILIO.COM/2010-04-01/ACCOUNTS/AC03C2FCD60E144E7CBEEE413FCBF812A3/APPLICATIONS.JSON
?_VOICEMETHOD=POST&_FRIENDLYNAME=TESTAPP1}

15:47:41.131 (1131115919)|STATEMENT_EXECUTE|[76]
15:47:41.131 (1131118479)|STATEMENT_EXECUTE|[77]
15:47:41.131 (1131122245)|HEAP_ALLOCATE|[77]|Bytes:61
15:47:41.131 (1131129477)|HEAP_ALLOCATE|[77]|Bytes:199
15:47:41.131 (1131149958)|USER_DEBUG|

[77]|DEBUG|Twilio_TestHTTPMock::getResponse() Did not find Resource for GET
https://api.twilio.com/2010-04-01/Accounts/AC03c2fcd60e144e7cbeee413fcbf812a3/Applications.json
?FriendlyName=Testapp1&VoiceMethod=POST

Henry Hai
twilio cloud communications
Expert Services
e: [email protected]
m: (718) 757-7157

On Mon, Jan 18, 2016 at 4:49 PM, cconroy222 [email protected]
wrote:

Switched the order of the puts for the map and the same issue persists.

Twilio_testApplication log.txt
https://github.com/twilio/twilio-salesforce/files/95043/Twilio_testApplication.log.txt


Reply to this email directly or view it on GitHub
#56 (comment)
.

@cconroy222
Copy link
Author

Yeah, I've attached my test class as well as the debug log. Should I be updating it somewhere outside of this class?
Twilo_testApplication.txt
Debug.txt

@hhai
Copy link
Contributor

hhai commented Jan 19, 2016

The test class you have attached is missing the parameters that should
match the Mock HTTP URL (bold).

Twilio_TestHTTPMock.getInstance().putResponse(
'GET',
'https://api.twilio.com/2010-04-01/Accounts/AC03c2fcd60e144e7cbeee413fcbf812a3/Applications.json
https://api.twilio.com/2010-04-01/Accounts/AC03c2fcd60e144e7cbeee413fcbf812a3/Applications.json

',
new Twilio_TestHTTPMock.Response(accountJsonResponseBody,200)
);

There should be "?VoiceMethod=POST&FriendlyName=Testapp1" in the URL
Please add that parameters back into the url for the Twilio_testHTTPMock
putResponse call so it matches the the Twilio Rest Client request that is
made later in the code (below).

map<String,String> params=new map<String,String>();
params.put('VoiceMethod','POST');
params.put('FriendlyName','Testapp1');
// Get an API client and request the Twilio Account
TwilioRestClient client = new
TwilioRestClient('AC03c2fcd60e144e7cbeee413fcbf812a3', authToken);
TwilioApplicationList twapps =
client.getAccount().getApplications(params);

On Mon, Jan 18, 2016 at 9:08 PM, cconroy222 [email protected]
wrote:

Yeah, I've attached my test class as well as the debug log. Should I be
updating it somewhere outside of this class?
Twilo_testApplication.txt
https://github.com/twilio/twilio-salesforce/files/95227/Twilo_testApplication.txt
Debug.txt
https://github.com/twilio/twilio-salesforce/files/95226/Debug.txt


Reply to this email directly or view it on GitHub
#56 (comment)
.

@cconroy222
Copy link
Author

That did it! Thanks for your help.

@dougturnkey
Copy link

Why don't you guys fix the unit tests in the install?!

@edmondop
Copy link

Guys I have just fixed this #64

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants