These are chat archives for aws/aws-sdk-php

1st
Oct 2015
kevin olson
@acidjazz
Oct 01 2015 20:28
hi everyone
Jonathan Eskew
@jeskew
Oct 01 2015 20:28
hi
kevin olson
@acidjazz
Oct 01 2015 20:28
looking for a good example to properly catch sdk exceptions
Jonathan Eskew
@jeskew
Oct 01 2015 20:28
with v3?
or v2?
kevin olson
@acidjazz
Oct 01 2015 20:29
let me check
3.0
looks like $exception->getMessage() contains the error?
but its a combination of text and XML
Jonathan Eskew
@jeskew
Oct 01 2015 20:30
Yes
hmmm that’s not ideal
kevin olson
@acidjazz
Oct 01 2015 20:30
anything else tahts more ideal.. yea
Jonathan Eskew
@jeskew
Oct 01 2015 20:30
do you have an example?
kevin olson
@acidjazz
Oct 01 2015 20:30
This message was deleted
woops should have made that a snippet
Jonathan Eskew
@jeskew
Oct 01 2015 20:30
no worries
kevin olson
@acidjazz
Oct 01 2015 20:31
string(651) "Error executing "Subscribe" on "https://sns.us-east-1.amazonaws.com"; AWS HTTP error: Client error: 403 AuthorizationError (client): User: arn:aws:iam::782785023246:root is not authorized to perform: SNS:Subscribe on resource: arn:aws:sns:us-east-1:932574457866:SMOA - <ErrorResponse xmlns="http://sns.amazonaws.com/doc/2010-03-31/">
  <Error>
    <Type>Sender</Type>
    <Code>AuthorizationError</Code>
    <Message>User: arn:aws:iam::782785023246:root is not authorized to perform: SNS:Subscribe on resource: arn:aws:sns:us-east-1:932574457866:SMOA</Message>
  </Error>
  <RequestId>12341fc4-61ca-564e-93f5-5143fbe61443</RequestId>
</ErrorResponse>
I'd like to pass through the error, preferably just the string
Is this coming from Guzzle or the SDK?
Jonathan Eskew
@jeskew
Oct 01 2015 20:31
the SDK
all SDK exceptions extend from Aws\AwsException
and have a method called getAwsErrorCode that returns the error string generated by the service
so in the example you provided getAwsErrorCode would return “AuthorizationError"
kevin olson
@acidjazz
Oct 01 2015 20:35
OK perfect
tahts plenty
I can then use getMessage() to get detail, but yea something more simple like that is what im looking for, thank you
Jonathan Eskew
@jeskew
Oct 01 2015 20:36
The code will always tell you the class of error if you want to take an action in certain circumstances
you might also want to upgrade
v3 follows semantic versioning, so all 3.x releases will be backwards compatible with 3.0