From 51cd189c034e83f356d6ba2ad9ca5b254f5f1729 Mon Sep 17 00:00:00 2001 From: Stanislav Mishchyshyn Date: Tue, 27 Feb 2024 20:22:54 +0200 Subject: [PATCH] feat: emit SeobotsGuardStreamError instead of plain error --- lib/errors.js | 3 +++ lib/streams/seobots-guard-stream.js | 10 ++++++---- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/lib/errors.js b/lib/errors.js index 94d4fd3..e7a2a7e 100644 --- a/lib/errors.js +++ b/lib/errors.js @@ -10,5 +10,8 @@ errors.FragmentError = extendError('FragmentError', { errors.FragmentWarn = extendError('FragmentWarn', { parent: errors.TailorError }); +errors.SeobotsGuardStreamError = extendError('SeobotsGuardStreamError', { + parent: errors.TailorError +}); module.exports = Object.freeze(errors); diff --git a/lib/streams/seobots-guard-stream.js b/lib/streams/seobots-guard-stream.js index 9889daf..d24a1f3 100644 --- a/lib/streams/seobots-guard-stream.js +++ b/lib/streams/seobots-guard-stream.js @@ -3,6 +3,7 @@ const stream = require('stream'); const BotDetector = require('device-detector-js/dist/parsers/bot'); const botDetector = new BotDetector(); +const errors = require('../errors'); /** * The goals of this stream is to change behaviour of the Tailor when dealing with SEO/SM bots. @@ -12,7 +13,7 @@ const botDetector = new BotDetector(); * * @type {module.StringifierStream} */ -module.exports = class StringifierStream extends stream.Transform { +module.exports = class SeobotStringifierStream extends stream.Transform { #response; #isBot = false; #fragmentsCounter = 0; @@ -127,9 +128,10 @@ module.exports = class StringifierStream extends stream.Transform { if (!this.#erroredState) { this.emit( 'error', - new Error( - 'Fragment error while processing request from SEO/SM bot. See adjacent messages for real cause.' - ) + new errors.SeobotsGuardStreamError({ + message: + 'Fragment error while processing request from SEO/SM bot. See adjacent messages for real cause.' + }) ); }