Skip to content

Commit 6d4bfba

Browse files
authored
Merge pull request #17 from twitterdev/undefined-url-module
Add URL module and fix error messages in CLI
2 parents 4432937 + 2ec5414 commit 6d4bfba

File tree

6 files changed

+19
-8
lines changed

6 files changed

+19
-8
lines changed

cli.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,9 @@ const subscribe = async (auth) => {
4444
try {
4545
webhook.subscribe(auth);
4646
} catch(e) {
47-
switch (e.constructor.name) {
48-
case UserSubscriptionError.name:
49-
console.error(e.getMessage());
47+
switch (e.constructor) {
48+
case UserSubscriptionError:
49+
console.error(e.message);
5050
break;
5151
}
5252

@@ -64,15 +64,15 @@ const subscribe = async (auth) => {
6464
try {
6565
await webhook.start(argv.webhookUrl || null);
6666
} catch(e) {
67-
switch (e.constructor.name) {
68-
case TooManyWebhooksError.name:
67+
switch (e.constructor) {
68+
case TooManyWebhooksError:
6969
console.error('Cannot add webhook: you have exceeded the number of webhooks available',
7070
`to you for the '${argv.env || process.env.TWITTER_WEBHOOK_ENV}' environment.`,
7171
`Use 'autohook -r' to remove your existing webhooks or remove callbacks manually`,
7272
'using the Twitter API.');
7373
break;
7474
default:
75-
console.error('Error:', e.getMessage());
75+
console.error('Error:', e.message);
7676
break;
7777
}
7878

errors/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ class RateLimitError extends Error {
4646
Error.captureStackTrace(this, this.constructor);
4747
}
4848
}
49-
class TooManySubscriptionsError extends Error {}
49+
class TooManySubscriptionsError extends TwitterError {}
5050

5151
module.exports = {
5252
TwitterError,

index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ const crypto = require('crypto');
99
const path = require('path');
1010
const os = require('os');
1111
const EventEmitter = require('events');
12+
const URL = require('url').URL;
13+
1214
const {
1315
TooManySubscriptionsError,
1416
UserSubscriptionError,

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "twitter-autohook",
3-
"version": "1.4.1",
3+
"version": "1.4.2",
44
"description": "Automatically setup and serve webhooks for the Twitter Account Activity API",
55
"repository": {
66
"type": "git",

test/errors.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ const {
33
UserSubscriptionError,
44
WebhookURIError,
55
RateLimitError,
6+
TooManySubscriptionsError,
67
} = require('../errors');
78
const response = {
89
statusCode: 200,
@@ -30,6 +31,7 @@ const assert = (e) => {
3031

3132
console.log(e.code === 1337);
3233
}
34+
3335
try {
3436
throw new TwitterError(response);
3537
} catch(e) {
@@ -53,3 +55,9 @@ try {
5355
} catch(e) {
5456
assert(e);
5557
}
58+
59+
try {
60+
throw new TooManySubscriptionsError(response);
61+
} catch(e) {
62+
assert(e);
63+
}

test/listen.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ const readline = require('readline').createInterface({
99
const util = require('util');
1010
const path = require('path');
1111
const os = require('os');
12+
const URL = require('url').URL;
1213

1314
const get = util.promisify(request.get);
1415
const post = util.promisify(request.post);

0 commit comments

Comments
 (0)