Skip to content

Commit

Permalink
feat: emit SeobotsGuardStreamError instead of plain error
Browse files Browse the repository at this point in the history
  • Loading branch information
stas-nc committed Feb 27, 2024
1 parent da8c354 commit 51cd189
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
3 changes: 3 additions & 0 deletions lib/errors.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
10 changes: 6 additions & 4 deletions lib/streams/seobots-guard-stream.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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;
Expand Down Expand Up @@ -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.'
})
);
}

Expand Down

0 comments on commit 51cd189

Please sign in to comment.