lib/services/s3.js
function extractError(resp) {
    var codes = {
      304: 'NotModified',
      403: 'Forbidden',
      400: 'BadRequest',
      404: 'NotFound'
    };

    var req = resp.request;
    var code = resp.httpResponse.statusCode;
    var body = resp.httpResponse.body || '';

    var headers = resp.httpResponse.headers || {};
    var region = headers['x-amz-bucket-region'] || null;
    var bucket = req.params.Bucket || null;
    var bucketRegionCache = req.service.bucketRegionCache;
    if (region && bucket && region !== bucketRegionCache[bucket]) {
      bucketRegionCache[bucket] = region;
    }

    var cachedRegion;
    if (codes[code] && body.length === 0) {
      if (bucket && !region) {
        cachedRegion = bucketRegionCache[bucket] || null;
        if (cachedRegion !== req.httpRequest.region) {
          region = cachedRegion;
        }
      }
      resp.error = AWS.util.error(new Error(), {
        code: codes[code],
        message: null,
        region: region
      });
    } else {
      var data = new AWS.XML.Parser().parse(body.toString());

      if (data.Region && !region) {
        region = data.Region;
        if (bucket && region !== bucketRegionCache[bucket]) {
          bucketRegionCache[bucket] = region;
        }
      } else if (bucket && !region && !data.Region) {
        cachedRegion = bucketRegionCache[bucket] || null;
        if (cachedRegion !== req.httpRequest.region) {
          region = cachedRegion;
        }
      }

      resp.error = AWS.util.error(new Error(), {
        code: data.Code || code,
        message: data.Message || null,
        region: region
      });
    }
    req.service.extractRequestIds(resp);
  }
function extractError(resp) {
    var codes = {
      304: 'NotModified',
      403: 'Forbidden',
      400: 'BadRequest',
      404: 'NotFound'
    };

    var req = resp.request;
    var code = resp.httpResponse.statusCode;
    var body = resp.httpResponse.body || '';

    var headers = resp.httpResponse.headers || {};
    var region = headers['x-amz-bucket-region'] || null;
    var bucket = req.params.Bucket || null;
    var bucketRegionCache = req.service.bucketRegionCache;
    if (region && bucket && region !== bucketRegionCache[bucket]) {
      bucketRegionCache[bucket] = region;
    }

    var cachedRegion;
    if (codes[code] && body.length === 0) {
      if (bucket && !region) {
        cachedRegion = bucketRegionCache[bucket] || null;
        if (cachedRegion !== req.httpRequest.region) {
          region = cachedRegion;
        }
      }
      resp.error = AWS.util.error(new Error(), {
        code: codes[code],
        message: null,
        region: region
      });
    } else {
      var data = new AWS.XML.Parser().parse(body.toString());

      if (data.Region && !region) {
        region = data.Region;
        if (bucket && region !== bucketRegionCache[bucket]) {
          bucketRegionCache[bucket] = region;
        }
      } else if (bucket && !region && !data.Region) {
        cachedRegion = bucketRegionCache[bucket] || null;
        if (cachedRegion !== req.httpRequest.region) {
          region = cachedRegion;
        }
      }

      resp.error = AWS.util.error(new Error(), {
        code: data.Code || code,
        message: data.Message || null,
        region: region
      });
    }
    req.service.extractRequestIds(resp);
  }
function extractError ( resp ) { var codes = { 304 : 'NotModified' , 403 : 'Forbidden' , 400 : 'BadRequest' , 404 : 'NotFound' } ; var req = resp . request ; var code = resp . httpResponse . statusCode ; var body = resp . httpResponse . body || '' ; var headers = resp . httpResponse . headers || { } ; var region = headers [ 'x-amz-bucket-region' ] || null ; var bucket = req . params . Bucket || null ; var bucketRegionCache = req . service . bucketRegionCache ; if ( region && bucket && region !== bucketRegionCache [ bucket ] ) { bucketRegionCache [ bucket ] = region ; } var cachedRegion ; if ( codes [ code ] && body . length === 0 ) { if ( bucket && ! region ) { cachedRegion = bucketRegionCache [ bucket ] || null ; if ( cachedRegion !== req . httpRequest . region ) { region = cachedRegion ; } } resp . error = AWS . util . error ( new Error ( ) , { code : codes [ code ] , message : null , region : region } ) ; } else { var data = new AWS . XML . Parser ( ) . parse ( body . toString ( ) ) ; if ( data . Region && ! region ) { region = data . Region ; if ( bucket && region !== bucketRegionCache [ bucket ] ) { bucketRegionCache [ bucket ] = region ; } } else if ( bucket && ! region && ! data . Region ) { cachedRegion = bucketRegionCache [ bucket ] || null ; if ( cachedRegion !== req . httpRequest . region ) { region = cachedRegion ; } } resp . error = AWS . util . error ( new Error ( ) , { code : data . Code || code , message : data . Message || null , region : region } ) ; } req . service . extractRequestIds ( resp ) ; }
Extracts an error object from the http response.

@api private
Extracts an error object from the http response .