chore: improved fetch operations feedbacks
This commit is contained in:
parent
f659afffd2
commit
513f6ca1c2
File diff suppressed because one or more lines are too long
@ -987,13 +987,14 @@ export default {
|
|||||||
this.loggedInViaDeezer(res.arl)
|
this.loggedInViaDeezer(res.arl)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
loginWithCredentials() {
|
async loginWithCredentials() {
|
||||||
const fromLoginForm = getFormItem(this.$refs.loginWithCredentialsForm)
|
const fromLoginForm = getFormItem(this.$refs.loginWithCredentialsForm)
|
||||||
|
|
||||||
const { username } = fromLoginForm('username')
|
const { username } = fromLoginForm('username')
|
||||||
const { password } = fromLoginForm('password')
|
const { password } = fromLoginForm('password')
|
||||||
|
|
||||||
postToServer('loginWithCredentials', { username, password })
|
const response = await postToServer('loginWithCredentials', { username, password })
|
||||||
|
console.log({ response })
|
||||||
},
|
},
|
||||||
appLogin() {
|
appLogin() {
|
||||||
socket.emit('applogin')
|
socket.emit('applogin')
|
||||||
|
@ -6,8 +6,15 @@ export function fetchData(key, data = {}, method = 'GET') {
|
|||||||
})
|
})
|
||||||
|
|
||||||
return fetch(url.href, { method })
|
return fetch(url.href, { method })
|
||||||
.then(response => response.json())
|
.then(response => {
|
||||||
.catch(() => {})
|
if (!response.ok) {
|
||||||
|
throw new Error('Network response was not ok')
|
||||||
|
}
|
||||||
|
return response.json()
|
||||||
|
})
|
||||||
|
.catch(error => {
|
||||||
|
console.error('There has been a problem with your fetch operation:', error)
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
export function sendToServer(key, data) {
|
export function sendToServer(key, data) {
|
||||||
@ -17,17 +24,28 @@ export function sendToServer(key, data) {
|
|||||||
url.searchParams.append(key, data[key])
|
url.searchParams.append(key, data[key])
|
||||||
})
|
})
|
||||||
|
|
||||||
fetch(url.href).catch(console.error)
|
fetch(url.href).catch(error => {
|
||||||
|
console.error('There has been a problem with your fetch operation:', error)
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
export const postToServer = (endpoint, data) => {
|
export const postToServer = (endpoint, data) => {
|
||||||
const url = new URL(`${window.location.origin}/api/${endpoint}`)
|
const url = new URL(`${window.location.origin}/api/${endpoint}`)
|
||||||
|
|
||||||
fetch(url, {
|
return fetch(url, {
|
||||||
body: JSON.stringify(data),
|
body: JSON.stringify(data),
|
||||||
headers: {
|
headers: {
|
||||||
'Content-Type': 'application/json'
|
'Content-Type': 'application/json'
|
||||||
},
|
},
|
||||||
method: 'POST'
|
method: 'POST'
|
||||||
}).catch(console.error)
|
})
|
||||||
|
.then(response => {
|
||||||
|
if (!response.ok) {
|
||||||
|
throw new Error('Network response was not ok')
|
||||||
|
}
|
||||||
|
return response.json()
|
||||||
|
})
|
||||||
|
.catch(error => {
|
||||||
|
console.error('There has been a problem with your fetch operation:', error)
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user