client/js/s3/s3.xhr.upload.handler.js
function(awsResponseXml) {
                    var parser = new DOMParser(),
                        parsedDoc = parser.parseFromString(awsResponseXml, "application/xml"),
                        errorEls = parsedDoc.getElementsByTagName("Error"),
                        errorDetails = {},
                        codeEls, messageEls;

                    if (errorEls.length) {
                        codeEls = parsedDoc.getElementsByTagName("Code");
                        messageEls = parsedDoc.getElementsByTagName("Message");

                        if (messageEls.length) {
                            errorDetails.message = messageEls[0].textContent;
                        }

                        if (codeEls.length) {
                            errorDetails.code = codeEls[0].textContent;
                        }

                        return errorDetails;
                    }
                }
function(awsResponseXml) {
                    var parser = new DOMParser(),
                        parsedDoc = parser.parseFromString(awsResponseXml, "application/xml"),
                        errorEls = parsedDoc.getElementsByTagName("Error"),
                        errorDetails = {},
                        codeEls, messageEls;

                    if (errorEls.length) {
                        codeEls = parsedDoc.getElementsByTagName("Code");
                        messageEls = parsedDoc.getElementsByTagName("Message");

                        if (messageEls.length) {
                            errorDetails.message = messageEls[0].textContent;
                        }

                        if (codeEls.length) {
                            errorDetails.code = codeEls[0].textContent;
                        }

                        return errorDetails;
                    }
                }
function ( awsResponseXml ) { var parser = new DOMParser ( ) , parsedDoc = parser . parseFromString ( awsResponseXml , "application/xml" ) , errorEls = parsedDoc . getElementsByTagName ( "Error" ) , errorDetails = { } , codeEls , messageEls ; if ( errorEls . length ) { codeEls = parsedDoc . getElementsByTagName ( "Code" ) ; messageEls = parsedDoc . getElementsByTagName ( "Message" ) ; if ( messageEls . length ) { errorDetails . message = messageEls [ 0 ] . textContent ; } if ( codeEls . length ) { errorDetails . code = codeEls [ 0 ] . textContent ; } return errorDetails ; } }
This parses an XML response by extracting the "Message" and "Code" elements that accompany AWS error responses.

@param awsResponseXml XML response from AWS
@returns {object} Object w/ `code` and `message` properties, or undefined if we couldn't find error info in the XML document.
This parses an XML response by extracting the Message and Code elements that accompany AWS error responses .