fix error handling

This commit is contained in:
Mészáros Mihály
2017-04-06 08:03:36 +02:00
parent ec1ba7a124
commit a4500d1763

View File

@@ -46,14 +46,22 @@ export default function authorize ( auth, authActions, errActions, configs ) {
"&scope=" + encodeURIComponent(scopes.join(scopeSeparator)) "&scope=" + encodeURIComponent(scopes.join(scopeSeparator))
}) })
.then(function (response) { .then(function (response) {
response.json() if ( !response.ok ) {
.then(function (json){ errActions.newAuthErr( {
authActions.authorizeOauth2({ auth, token: json }) authId: name,
}) level: "error",
}) source: "auth",
.catch (function (error) { message: response.statusText
console.log("POST Request failed", error) } )
return
} else {
response.json()
.then(function (json){
authActions.authorizeOauth2({ auth, token: json})
})
}
}) })
.catch(err => { errActions.newAuthErr( err ) })
} else { } else {
// pass action authorizeOauth2 and authentication data through window // pass action authorizeOauth2 and authentication data through window
// to authorize with oauth2 // to authorize with oauth2