2017-11-28 1 views
0

Ich habe Authentifizierungsschema Implementierung wie dieseHapi js Authentifizierungsschema Implementierungsfehler/Fehler?

const schemeImplementation = (server, options) => { 
    return { 
    authenticate: (request, reply) => { 
     authenticate(request) 
     .then((credentials) => { 
     return reply.continue({ credentials }); 
     }) 
     .catch((err) => { 
     // not returning any response instead of timeout 
     return reply(err); 
     }); 
    } 
    }; 
}; 

und in Route Handler

handler: (req, reply) => { 
    throw new Error('This shouldn\'t lead to a timeout'); 
} 

Ich erwarte es die Fehlerreaktion korrekt zurückgibt. Hat jemand das schon mal mit Hapi erlebt?

Hinweise: es geschieht nur, wenn synchron eine Ausnahme ref werfen: https://hapijs.com/api#authentication-scheme

Antwort

0

IMO, der bessere Weg, den Fehler über Boom Plugin erneut zu senden. Ich verwende so: -

const schemeImplementation = (server, options) => { 
    return { 
    authenticate: (request, reply) => { 
     authenticate(request) 
     .then((credentials) => { 
     return reply.continue({ credentials }); 
     }) 
     .catch((err) => { 
     // this way it will directly return the error to client and would not go handler 
     reply(Boom.badGateway(err)); 
     }); 
    } 
    }; 
}; 
Verwandte Themen