Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: emit SeobotsGuardStreamError instead of plain error #2

Merged
merged 2 commits into from
Mar 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading