Use status code as fallback to status message for error responses (#1045)

Use status code as fallback to the status message for error responses to detect whether the
initial requests are unauthorized (HTTP 401).
(With HTTP2 there is no status message and even in HTTP1 it is optional.)

Fix #1018.

Signed-off-by: Leon Kiefer <leon.k97@gmx.de>
pull/1051/head
Leon Kiefer 2021-05-11 16:26:53 +02:00 committed by GitHub
parent 1b002cf76d
commit 4e402ef697
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 6 additions and 6 deletions

View File

@ -378,7 +378,7 @@ export default {
return useCredentialsPromise
.then(() => { return this.$oh.api.get('/rest/') })
.catch((err) => {
if (err === 'Unauthorized') {
if (err === 'Unauthorized' || err === 401) {
if (!useCredentials) {
// try again with credentials
this.loadData(true)
@ -395,7 +395,7 @@ export default {
this.storeBasicCredentials()
this.loadData()
}).catch((err) => {
if (err === 'Unauthorized') {
if (err === 'Unauthorized' || err === 401) {
this.clearBasicCredentials()
this.loadData()
return Promise.reject()

View File

@ -4,8 +4,8 @@ import { getAccessToken, getTokenInCustomHeader, getBasicCredentials } from './a
function wrapPromise (f7promise) {
return new Promise((resolve, reject) => {
f7promise
.then((data) => resolve(data.data, data.status, data.xhr))
.catch((err) => reject(err.message, err.status, err.xhr))
.then((data) => resolve(data.data))
.catch((err) => reject(err.message || err.status))
})
}

View File

@ -92,7 +92,7 @@ export function setAccessToken (token, api) {
requireToken = false
return Promise.resolve()
}).catch((err) => {
if (err === 'Unauthorized') requireToken = true
if (err === 'Unauthorized' || err === 401) requireToken = true
return Promise.resolve()
})
}

View File

@ -124,7 +124,7 @@ export default {
})
.catch((err) => {
console.log('Error while loading model: ' + err)
if (err === 'Unauthorized') {
if (err === 'Unauthorized' || err === 401) {
authorize()
}
})