Skip to content

Commit

Permalink
fixed wrong use of resolve and reject
Browse files Browse the repository at this point in the history
added workaround for empty reason-phrase

Signed-off-by: Leon Kiefer <leon.k97@gmx.de>
  • Loading branch information
Legion2 committed May 11, 2021
1 parent d605929 commit 5f6f0d6
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 8 deletions.
8 changes: 4 additions & 4 deletions bundles/org.openhab.ui/web/src/components/app.vue
Original file line number Diff line number Diff line change
Expand Up @@ -376,8 +376,8 @@ export default {
const useCredentialsPromise = (useCredentials) ? this.setBasicCredentials() : Promise.resolve()
return useCredentialsPromise
.then(() => { return this.$oh.api.get('/rest/') })
.catch((err, status) => {
if (status === 401) {
.catch((err) => {
if (err === 'Unauthorized' || err === 401) {
if (!useCredentials) {
// try again with credentials
this.loadData(true)
Expand All @@ -393,8 +393,8 @@ export default {
this.$oh.api.get('/rest/').then((rootResponse) => {
this.storeBasicCredentials()
this.loadData()
}).catch((err, status) => {
if (status === 401) {
}).catch((err) => {
if (err === 'Unauthorized' || err === 401) {
this.clearBasicCredentials()
this.loadData()
return Promise.reject()
Expand Down
4 changes: 2 additions & 2 deletions bundles/org.openhab.ui/web/src/js/openhab/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -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))
})
}

Expand Down
2 changes: 1 addition & 1 deletion bundles/org.openhab.ui/web/src/js/openhab/auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()
})
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ export default {
})
.catch((err) => {
console.log('Error while loading model: ' + err)
if (err === 'Unauthorized') {
if (err === 'Unauthorized' || err === 401) {
authorize()
}
})
Expand Down

0 comments on commit 5f6f0d6

Please sign in to comment.