Skip to content

Commit

Permalink
Merge pull request #2 from namecheap/feature/seobot-error
Browse files Browse the repository at this point in the history
feat: emit SeobotsGuardStreamError instead of plain error
  • Loading branch information
stas-nc authored Mar 6, 2024
2 parents da8c354 + c5b8045 commit fc5bd3d
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 7 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
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@namecheap/tailorx",
"version": "8.0.0",
"version": "8.1.0",
"description": "Tailor assembles a web page from multiple fragments",
"keywords": [
"tailor",
Expand Down

0 comments on commit fc5bd3d

Please sign in to comment.