123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354 |
- /**
- * exception-stream.js: TODO: add file header handler.
- *
- * (C) 2010 Charlie Robbins
- * MIT LICENCE
- */
- 'use strict';
- const Writable = require('readable-stream/writable');
- /**
- * TODO: add class description.
- * @type {ExceptionStream}
- * @extends {Writable}
- */
- module.exports = class ExceptionStream extends Writable {
- /**
- * Constructor function for the ExceptionStream responsible for wrapping a
- * TransportStream; only allowing writes of `info` objects with
- * `info.exception` set to true.
- * @param {!TransportStream} transport - Stream to filter to exceptions
- */
- constructor(transport) {
- super({ objectMode: true });
- if (!transport) {
- throw new Error('ExceptionStream requires a TransportStream instance.');
- }
- // Remark (indexzero): we set `handleExceptions` here because it's the
- // predicate checked in ExceptionHandler.prototype.__getExceptionHandlers
- this.handleExceptions = true;
- this.transport = transport;
- }
- /**
- * Writes the info object to our transport instance if (and only if) the
- * `exception` property is set on the info.
- * @param {mixed} info - TODO: add param description.
- * @param {mixed} enc - TODO: add param description.
- * @param {mixed} callback - TODO: add param description.
- * @returns {mixed} - TODO: add return description.
- * @private
- */
- _write(info, enc, callback) {
- if (info.exception) {
- return this.transport.log(info, callback);
- }
- callback();
- return true;
- }
- };
|