About this question
I'm trying to create an Apex callout and running into the following error message: System.UnexpectedException: Script-thrown exception My analysis shows that System.UnexpectedException is not catchable in Apex. There are some reports of exceptions with “Script-thrown exception” message by other users, but the exception type in those cases happen to be System.CalloutException. [1] The only reported case of a System.UnexpectedException with the same message appears to be triggered by log level of Callouts. (Note: the recommended workaround did not solve the problem in our case.) [2]
This is the code that causes the error:
HttpRequest req = new HttpRequest(); req.setEndpoint('callout:AmazonConnectAPI/contact/start-recording'); req.setMethod('POST'); String body = String.format( ''{'"ContactId": "{0}","InitialContactId": "{1}","InstanceId": "{2}","VoiceRecordingConfiguration": '{'"VoiceRecordingTrack": "{3}"'}''}'', new List{ contactId, initialContactId, instanceId, voiceRecordingTrack } ); if (body != '') { req.setBody(body); } Http http = new Http(); HttpResponse resp = http.send(req);
Other notable facts:
- The HTTP callout is made to a Named Credential called AmazonConnectAPI
- AmazonConnectAPI is configured for "https://connect.us-east-1.amazonaws.com“
- The authentication method of the Named Credential is Named Principal with protocol "AWS Signature Version 4
- The authentication method uses the credentials for an IAM user with a full-access managed policy to Amazon Connect.
- The formatting of the body is correct. There is no syntax error.
- The error comes from this line HttpResponse resp = http.send(req);