API Guide
7
Exception Handling
When an HTTP error code is returned the response payload will contain information about the error that occurred. For the purpose
of illustration the following exception response was intentionally generated by trying to get a ServiceTemplate with an id that doesn't
exist. In this case the HTTP response was 404 and the XML response is below. See the API reference section for the relevant HTTP
responses that may be returned by each REST endpoint.
The example code used to catch this exception and report the error is below.
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<AsmDetailedMessageList>
<Messages>
<messages>
<messageBundle>AsmManagerMessages</messageBundle>
<messageCode>ASM0042</messageCode>
<severity>ERROR</severity>
<category>USER_FACING</category>
<displayMessage>Unable to find the Template Id: ABC.</displayMessage>
<responseAction>Make sure that a correct Template Id is entered and retry the
operation. Template Ids are case sensitive. Verify the list of devices under the Summary
tab to make sure whether or not the Template already exists.</responseAction>
<detailedMessage>The Template Id cannot be found.</detailedMessage>
<agentId>ASM Manager</agentId>
<timeStamp>2015-03-10T14:34:24.866Z</timeStamp>
<sequenceNumber>0</sequenceNumber>
</messages>
</Messages>
</AsmDetailedMessageList>
require 'ASMConfig'
templateId = "ABC" // bogus id
url = ASM::API::URI("/ServiceTemplate/%s"%templateId)
begin
response = ASM::API::sign {
RestClient.get url
}
rescue RestClient::Exception => e
print "Got exception with status: %d\n" % e.response.code
print "%s\n" % e.response
end
23