lib/s3rver.js
function onerror(err) {
  // don't do anything if there is no error.
  // this allows you to pass `this.onerror`
  // to node-style callbacks.
  if (null == err) return;

  if (!(err instanceof Error))
    err = new Error(format("non-error thrown: %j", err));

  let headerSent = false;
  if (this.headerSent || !this.writable) {
    headerSent = err.headerSent = true;
  }

  // delegate
  this.app.emit("error", err, this);

  // nothing we can do here other
  // than delegate to the app-level
  // handler and log.
  if (headerSent) {
    return;
  }

  const { res } = this;

  if (!(err instanceof S3Error)) {
    err = S3Error.fromError(err);
  }

  // first unset all headers
  res
    .getHeaderNames()
    .filter(name => !name.match(/^access-control-|vary|x-amz-/i))
    .forEach(name => res.removeHeader(name));

  // (the presence of x-amz-error-* headers needs additional research)
  // this.set(err.headers);

  // force application/xml
  this.type = "application/xml";

  // respond
  const msg = err.toXML();
  this.status = err.status;
  this.length = Buffer.byteLength(msg);
  res.end(msg);
}
function onerror(err) {
  // don't do anything if there is no error.
  // this allows you to pass `this.onerror`
  // to node-style callbacks.
  if (null == err) return;

  if (!(err instanceof Error))
    err = new Error(format("non-error thrown: %j", err));

  let headerSent = false;
  if (this.headerSent || !this.writable) {
    headerSent = err.headerSent = true;
  }

  // delegate
  this.app.emit("error", err, this);

  // nothing we can do here other
  // than delegate to the app-level
  // handler and log.
  if (headerSent) {
    return;
  }

  const { res } = this;

  if (!(err instanceof S3Error)) {
    err = S3Error.fromError(err);
  }

  // first unset all headers
  res
    .getHeaderNames()
    .filter(name => !name.match(/^access-control-|vary|x-amz-/i))
    .forEach(name => res.removeHeader(name));

  // (the presence of x-amz-error-* headers needs additional research)
  // this.set(err.headers);

  // force application/xml
  this.type = "application/xml";

  // respond
  const msg = err.toXML();
  this.status = err.status;
  this.length = Buffer.byteLength(msg);
  res.end(msg);
}
function onerror ( err ) { // don't do anything if there is no error. // this allows you to pass `this.onerror` // to node-style callbacks. if ( null == err ) return ; if ( ! ( err instanceof Error ) ) err = new Error ( format ( "non-error thrown: %j" , err ) ) ; let headerSent = false ; if ( this . headerSent || ! this . writable ) { headerSent = err . headerSent = true ; } // delegate this . app . emit ( "error" , err , this ) ; // nothing we can do here other // than delegate to the app-level // handler and log. if ( headerSent ) { return ; } const { res } = this ; if ( ! ( err instanceof S3Error ) ) { err = S3Error . fromError ( err ) ; } // first unset all headers res . getHeaderNames ( ) . filter ( name => ! name . match ( / ^access-control-|vary|x-amz- / i ) ) . forEach ( name => res . removeHeader ( name ) ) ; // (the presence of x-amz-error-* headers needs additional research) // this.set(err.headers); // force application/xml this . type = "application/xml" ; // respond const msg = err . toXML ( ) ; this . status = err . status ; this . length = Buffer . byteLength ( msg ) ; res . end ( msg ) ; }
Koa context.onerror handler modified to write a XML-formatted response body
@param {Error} err
Koa context . onerror handler modified to write a XML - formatted response body