I'd prefer a more structured approach.  Is the code attribute not available from the s3 exception object?