This repository has been archived by the owner on Sep 28, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 81
(semver-minor) define/export error constants #105
Open
techjeffharris
wants to merge
5
commits into
jfromaniello:master
Choose a base branch
from
techjeffharris:export_error_constants
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 2 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
1eb16ae
define/export error constants
techjeffharris d968366
replaced ERROR_NOT_AUTHORIZED with ERROR_USER_NOT_AUTHORIZED
techjeffharris 7bea97d
moved \n to line 79
techjeffharris 5c9f05f
add PassportSocketIoError
techjeffharris 3077915
add constant `ERROR_DEFAULT` to PassportSocketIoError.prototype
techjeffharris File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,13 @@ | ||
var xtend = require('xtend'); | ||
|
||
var ERROR_CORS_REQUEST = 'Can not read cookies from CORS-Requests. See CORS-Workaround in the readme.'; | ||
var ERROR_NO_COOKIE_PARSER = 'cookieParser is required use require(\'cookie-parser\'), connect.cookieParser or express.cookieParser'; | ||
var ERROR_NO_SESSION = 'No session found'; | ||
var ERROR_PASSPORT_NOT_INITIALIZED = 'Passport was not initialized'; | ||
var ERROR_SESSION_STORE = 'Error in session store:\n'; | ||
var ERROR_USER_NOT_AUTHORIZED = 'User not authorized through passport. (User Property not found)'; | ||
var ERROR_USER_NOT_FOUND = 'User not found'; | ||
|
||
function parseCookie(auth, cookieHeader) { | ||
var cookieParser = auth.cookieParser(auth.secret); | ||
var req = { | ||
|
@@ -45,7 +53,7 @@ function authorize(options) { | |
try { | ||
auth.cookieParser = require('cookie-parser'); | ||
} catch (err) { | ||
throw new Error('cookieParser is required use require(\'cookie-parser\'), connect.cookieParser or express.cookieParser'); | ||
throw new Error(ERROR_NO_COOKIE_PARSER); | ||
} | ||
} | ||
|
||
|
@@ -64,26 +72,26 @@ function authorize(options) { | |
}; | ||
|
||
if(data.xdomain && !data.sessionID) | ||
return auth.fail(data, 'Can not read cookies from CORS-Requests. See CORS-Workaround in the readme.', false, accept); | ||
return auth.fail(data, ERROR_CORS_REQUEST, false, accept); | ||
|
||
auth.store.get(data.sessionID, function(err, session){ | ||
if(err) | ||
return auth.fail(data, 'Error in session store:\n' + err.message, true, accept); | ||
return auth.fail(data, ERROR_SESSION_STORE + err.message, true, accept); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since the session store error is going to be concatenated to this constant, one must search the error for a pattern/regexp that matches this constant to know its an external error, but that is better than that external error message never being passed at all. |
||
if(!session) | ||
return auth.fail(data, 'No session found', false, accept); | ||
return auth.fail(data, ERROR_NO_SESSION, false, accept); | ||
if(!session[auth.passport._key]) | ||
return auth.fail(data, 'Passport was not initialized', true, accept); | ||
return auth.fail(data, ERROR_PASSPORT_NOT_INITIALIZED, true, accept); | ||
|
||
var userKey = session[auth.passport._key][auth.userProperty]; | ||
|
||
if(typeof(userKey) === 'undefined') | ||
return auth.fail(data, 'User not authorized through passport. (User Property not found)', false, accept); | ||
return auth.fail(data, ERROR_USER_NOT_AUTHORIZED, false, accept); | ||
|
||
auth.passport.deserializeUser(userKey, data, function(err, user) { | ||
if (err) | ||
return auth.fail(data, err, true, accept); | ||
if (!user) | ||
return auth.fail(data, "User not found", false, accept); | ||
return auth.fail(data, ERROR_USER_NOT_FOUND, false, accept); | ||
data[auth.userProperty] = user; | ||
data[auth.userProperty].logged_in = true; | ||
auth.success(data, accept); | ||
|
@@ -110,3 +118,11 @@ function filterSocketsByUser(socketIo, filter){ | |
|
||
exports.authorize = authorize; | ||
exports.filterSocketsByUser = filterSocketsByUser; | ||
|
||
exports.ERROR_CORS_REQUEST = ERROR_CORS_REQUEST; | ||
exports.ERROR_NO_COOKIE_PARSER = ERROR_NO_COOKIE_PARSER; | ||
exports.ERROR_NO_SESSION = ERROR_NO_SESSION; | ||
exports.ERROR_PASSPORT_NOT_INITIALIZED = ERROR_PASSPORT_NOT_INITIALIZED; | ||
exports.ERROR_SESSION_STORE = ERROR_SESSION_STORE; | ||
exports.ERROR_USER_NOT_AUTHORIZED = ERROR_USER_NOT_AUTHORIZED; | ||
exports.ERROR_USER_NOT_FOUND = ERROR_USER_NOT_FOUND; |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
\n
should probably not be in the constant.. I'll move it to the message concatenaed to it on line 79.