[Pkg-javascript-commits] [sockjs-client] 203/350: Remove custom errors. Too much trouble.

tonnerre at ancient-solutions.com tonnerre at ancient-solutions.com
Fri Aug 5 01:04:21 UTC 2016


This is an automated email from the git hooks/post-receive script.

tonnerre-guest pushed a commit to branch upstream
in repository sockjs-client.

commit b21207541bd8b7e1a4a413b6e1d27ad8204f5b02
Author: Bryce Kahle <bkahle at gmail.com>
Date:   Mon Oct 20 17:18:58 2014 -0400

    Remove custom errors. Too much trouble.
---
 lib/error/invalid-access.js |  9 ---------
 lib/error/invalid-state.js  |  9 ---------
 lib/error/security.js       |  9 ---------
 lib/main.js                 | 11 ++++-------
 tests/lib/main-node.js      |  4 ++--
 5 files changed, 6 insertions(+), 36 deletions(-)

diff --git a/lib/error/invalid-access.js b/lib/error/invalid-access.js
deleted file mode 100644
index 892f58d..0000000
--- a/lib/error/invalid-access.js
+++ /dev/null
@@ -1,9 +0,0 @@
-'use strict';
-
-function InvalidAccessError() {
-}
-
-InvalidAccessError.prototype = new Error();
-InvalidAccessError.prototype.constructor = InvalidAccessError;
-
-module.exports = InvalidAccessError;
diff --git a/lib/error/invalid-state.js b/lib/error/invalid-state.js
deleted file mode 100644
index 3455b29..0000000
--- a/lib/error/invalid-state.js
+++ /dev/null
@@ -1,9 +0,0 @@
-'use strict';
-
-function InvalidStateError() {
-}
-
-InvalidStateError.prototype = new Error();
-InvalidStateError.prototype.constructor = InvalidStateError;
-
-module.exports = InvalidStateError;
diff --git a/lib/error/security.js b/lib/error/security.js
deleted file mode 100644
index b031b40..0000000
--- a/lib/error/security.js
+++ /dev/null
@@ -1,9 +0,0 @@
-'use strict';
-
-function SecurityError() {
-}
-
-SecurityError.prototype = new Error();
-SecurityError.prototype.constructor = SecurityError;
-
-module.exports = SecurityError;
diff --git a/lib/main.js b/lib/main.js
index 1a42195..51080b1 100644
--- a/lib/main.js
+++ b/lib/main.js
@@ -12,9 +12,6 @@ var u = require('url')
   , transport = require('./utils/transport')
   , objectUtils = require('./utils/object')
   , browser = require('./utils/browser')
-  , SecurityError = require('./error/security')
-  , InvalidAccessError = require('./error/invalid-access')
-  , InvalidStateError = require('./error/invalid-state')
   , Event = require('./event/event')
   , EventTarget = require('./event/eventtarget')
   , loc = require('./location')
@@ -65,7 +62,7 @@ function SockJS(url, protocols, transportsWhitelist) {
   var secure = parsedUrl.protocol === 'https:';
   // Step 2 - don't allow secure origin with an insecure protocol
   if (loc.protocol === 'https' && !secure) {
-    throw new SecurityError('An insecure SockJS connection may not be initiated from a page loaded over HTTPS');
+    throw new Error('SecurityError: An insecure SockJS connection may not be initiated from a page loaded over HTTPS');
   }
 
   // Step 3 - check port access - no need here
@@ -128,7 +125,7 @@ function userSetCode(code) {
 SockJS.prototype.close = function(code, reason) {
   // Step 1
   if (code && !userSetCode(code)) {
-    throw new InvalidAccessError('Invalid code');
+    throw new Error('InvalidAccessError: Invalid code');
   }
   // Step 2.4 states the max is 123 bytes, but we are just checking length
   if (reason && reason.length > 123) {
@@ -152,7 +149,7 @@ SockJS.prototype.send = function(data) {
     data = '' + data;
   }
   if (this.readyState === SockJS.CONNECTING) {
-    throw new InvalidStateError('The connection has not been established yet');
+    throw new Error('InvalidStateError: The connection has not been established yet');
   }
   if (this.readyState !== SockJS.OPEN) {
     return;
@@ -313,7 +310,7 @@ SockJS.prototype._close = function(code, reason, wasClean) {
   }
 
   if (this.readyState === SockJS.CLOSED) {
-    throw new InvalidStateError('SockJS has already been closed');
+    throw new Error('InvalidStateError: SockJS has already been closed');
   }
 
   this.readyState = SockJS.CLOSING;
diff --git a/tests/lib/main-node.js b/tests/lib/main-node.js
index fa84c4e..bbad4a6 100644
--- a/tests/lib/main-node.js
+++ b/tests/lib/main-node.js
@@ -2,7 +2,6 @@
 
 var expect = require('expect.js')
   , proxyquire = require('proxyquire')
-  , SecurityError = require('../../lib/error/security')
   ;
 
 describe('SockJS', function() {
@@ -17,7 +16,8 @@ describe('SockJS', function() {
         expect(function () {
           sjs('http://localhost');
         }).to.throwException(function (e) {
-          expect(e).to.be.a(SecurityError);
+          expect(e).to.be.a(Error);
+          expect(e).to.contain('SecurityError');
         });
       });
     });

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/sockjs-client.git



More information about the Pkg-javascript-commits mailing list