@@ -13,6 +13,7 @@ var async = require('async');
1313var _ = require ( 'underscore' ) ;
1414var BadRequestError = require ( '../errors/BadRequestError' ) ;
1515var ForbiddenError = require ( '../errors/ForbiddenError' ) ;
16+ var NotFoundError = require ( '../errors/NotFoundError' ) ;
1617var UnauthorizedError = require ( '../errors/UnauthorizedError' ) ;
1718var IllegalArgumentError = require ( '../errors/IllegalArgumentError' ) ;
1819
@@ -334,27 +335,33 @@ function getUserIdentityByAuth0Id(api, connection, next) {
334335 var helper = api . helper ,
335336 auth0id = connection . params . id ,
336337 userid = 0 ,
337- dbConnectionMap = connection . dbConnectionMap ,
338+ dbConnectionMap = connection . dbConnectionMap ,
339+ notfound = new NotFoundError ( 'Feelin lucky, punk?' ) ,
338340 response ;
339341
340342 async . waterfall ( [
341343 function ( cb ) {
342- var splits = auth0id . split ( '|' ) ;
343- if ( splits [ 0 ] == 'ad' ) {
344- cb ( null , [ { user_id : Number ( splits [ 1 ] ) } ] ) ;
345- } else {
346- api . helper . getProviderId ( splits [ 0 ] , function ( err , provider ) {
347- if ( err ) {
348- cb ( err ) ;
349- } else {
350- api . dataAccess . executeQuery ( "get_user_by_social_login" ,
351- {
352- social_user_id : splits [ 1 ] ,
353- provider_id : provider
354- } ,
355- dbConnectionMap , cb ) ;
356- }
357- } ) ;
344+ try {
345+ var splits = auth0id . split ( '|' ) ;
346+ if ( splits [ 0 ] == 'ad' ) {
347+ cb ( null , [ { user_id : Number ( splits [ 1 ] ) } ] ) ;
348+ } else {
349+ api . helper . getProviderId ( splits [ 0 ] , function ( err , provider ) {
350+ if ( err ) {
351+ cb ( notfound ) ;
352+ } else {
353+ api . dataAccess . executeQuery ( "get_user_by_social_login" ,
354+ {
355+ social_user_id : splits [ 1 ] ,
356+ provider_id : provider
357+ } ,
358+ dbConnectionMap , cb ) ;
359+ }
360+ } ) ;
361+ }
362+ }
363+ catch ( exc ) {
364+ cb ( notfound ) ;
358365 }
359366 } ,
360367 function ( result , cb ) {
@@ -364,12 +371,15 @@ function getUserIdentityByAuth0Id(api, connection, next) {
364371 dbConnectionMap , cb ) ;
365372 } ,
366373 function ( rs , cb ) {
367- response = {
368- uid : userid ,
369- handle : rs [ 0 ] . handle ,
370- email : rs [ 0 ] . address
371- } ;
372- cb ( ) ;
374+ if ( ! rs [ 0 ] ) {
375+ cb ( notfound ) ;
376+ } else {
377+ response = {
378+ uid : userid ,
379+ handle : rs [ 0 ] . handle
380+ } ;
381+ cb ( ) ;
382+ }
373383 }
374384 ] , function ( err ) {
375385 if ( err ) {
0 commit comments