mirror of
https://github.com/notherealmarco/WASAPhoto.git
synced 2025-03-14 14:16:15 +01:00
Fix error when there is no network connection
This commit is contained in:
parent
8613a5780f
commit
92522876b7
4 changed files with 40 additions and 34 deletions
|
@ -26,20 +26,20 @@ export default {
|
||||||
// Leave response as is
|
// Leave response as is
|
||||||
return response;
|
return response;
|
||||||
}, error => {
|
}, error => {
|
||||||
if (error.response != undefined) {
|
if (error.response.status != 0) {
|
||||||
// If the response is 401, redirect to /login
|
// If the response is 401, redirect to /login
|
||||||
if (error.response.status === 401) {
|
if (error.response.status === 401) {
|
||||||
this.$router.push({ path: '/login' })
|
this.$router.push({ path: '/login' })
|
||||||
return
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Show the error message from the server in a modal
|
// Show the error message from the server in a modal
|
||||||
this.showModal("Error " + error.response.status, error.response.data['status'])
|
this.showModal("Error " + error.response.status, error.response.data['status'])
|
||||||
return
|
return;
|
||||||
}
|
}
|
||||||
// Show the error message from axios in a modal
|
// Show the error message from axios in a modal
|
||||||
this.showModal("Error", error.toString());
|
this.showModal("Error", error.toString());
|
||||||
return error;
|
return;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,7 +3,7 @@ import getCurrentSession from "./authentication";
|
||||||
|
|
||||||
const instance = axios.create({
|
const instance = axios.create({
|
||||||
baseURL: __API_URL__,
|
baseURL: __API_URL__,
|
||||||
timeout: 1000 * 20
|
timeout: 1000 * 60
|
||||||
});
|
});
|
||||||
|
|
||||||
//axios.interceptors.request.use(function (config) {
|
//axios.interceptors.request.use(function (config) {
|
||||||
|
|
|
@ -2,12 +2,12 @@
|
||||||
export default {
|
export default {
|
||||||
data: function() {
|
data: function() {
|
||||||
return {
|
return {
|
||||||
errormsg: null,
|
|
||||||
loading: false,
|
loading: false,
|
||||||
stream_data: [],
|
stream_data: [],
|
||||||
data_ended: false,
|
data_ended: false,
|
||||||
start_idx: 0,
|
start_idx: 0,
|
||||||
limit: 1,
|
limit: 1,
|
||||||
|
loadingError: false,
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
|
@ -23,16 +23,18 @@ export default {
|
||||||
},
|
},
|
||||||
async loadContent() {
|
async loadContent() {
|
||||||
this.loading = true;
|
this.loading = true;
|
||||||
this.errormsg = null;
|
|
||||||
try {
|
|
||||||
let response = await this.$axios.get("/stream?start_index=" + this.start_idx + "&limit=" + this.limit);
|
let response = await this.$axios.get("/stream?start_index=" + this.start_idx + "&limit=" + this.limit);
|
||||||
|
|
||||||
|
if (response == null) {
|
||||||
|
this.loading = false
|
||||||
|
this.loadingError = true
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
if (response.data.length == 0) this.data_ended = true;
|
if (response.data.length == 0) this.data_ended = true;
|
||||||
else this.stream_data = this.stream_data.concat(response.data);
|
else this.stream_data = this.stream_data.concat(response.data);
|
||||||
this.loading = false;
|
this.loading = false;
|
||||||
} catch (e) {
|
|
||||||
// todo: handle better
|
|
||||||
this.errormsg = e.toString();
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
scroll () {
|
scroll () {
|
||||||
window.onscroll = () => {
|
window.onscroll = () => {
|
||||||
|
@ -58,8 +60,6 @@ export default {
|
||||||
<div class="col-xl-6 col-lg-9">
|
<div class="col-xl-6 col-lg-9">
|
||||||
<h3 class="card-title border-bottom mb-4 pb-2 text-center">Your daily WASAStream!</h3>
|
<h3 class="card-title border-bottom mb-4 pb-2 text-center">Your daily WASAStream!</h3>
|
||||||
|
|
||||||
<ErrorMsg v-if="errormsg" :msg="errormsg"></ErrorMsg>
|
|
||||||
|
|
||||||
<div v-if="(stream_data.length == 0)" class="alert alert-secondary text-center" role="alert">
|
<div v-if="(stream_data.length == 0)" class="alert alert-secondary text-center" role="alert">
|
||||||
There's nothing here 😢
|
There's nothing here 😢
|
||||||
<br />Why don't you start following somebody? 👻
|
<br />Why don't you start following somebody? 👻
|
||||||
|
@ -80,6 +80,7 @@ export default {
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<LoadingSpinner :loading="loading" /><br />
|
<LoadingSpinner :loading="loading" /><br />
|
||||||
|
<button v-if="loadingError" @click="refresh" class="btn btn-secondary w-100 py-3">Retry</button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -3,8 +3,10 @@ export default {
|
||||||
data: function () {
|
data: function () {
|
||||||
return {
|
return {
|
||||||
requestedProfile: this.$route.params.user_id,
|
requestedProfile: this.$route.params.user_id,
|
||||||
errormsg: null,
|
|
||||||
loading: false,
|
loading: false,
|
||||||
|
loadingError: false,
|
||||||
|
|
||||||
stream_data: [],
|
stream_data: [],
|
||||||
data_ended: false,
|
data_ended: false,
|
||||||
start_idx: 0,
|
start_idx: 0,
|
||||||
|
@ -27,26 +29,30 @@ export default {
|
||||||
},
|
},
|
||||||
|
|
||||||
async getMainData() {
|
async getMainData() {
|
||||||
try {
|
|
||||||
let response = await this.$axios.get("/users/" + this.requestedProfile);
|
let response = await this.$axios.get("/users/" + this.requestedProfile);
|
||||||
this.user_data = response.data;
|
|
||||||
} catch (e) {
|
if (response == null) {
|
||||||
this.errormsg = e.toString();
|
this.loading = false
|
||||||
|
this.loadingError = true
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
this.user_data = response.data;
|
||||||
},
|
},
|
||||||
|
|
||||||
async loadContent() {
|
async loadContent() {
|
||||||
this.loading = true;
|
this.loading = true;
|
||||||
this.errormsg = null;
|
|
||||||
try {
|
|
||||||
let response = await this.$axios.get("/users/" + this.requestedProfile + "/photos" + "?start_index=" + this.start_idx + "&limit=" + this.limit);
|
let response = await this.$axios.get("/users/" + this.requestedProfile + "/photos" + "?start_index=" + this.start_idx + "&limit=" + this.limit);
|
||||||
|
|
||||||
|
if (response == null) {
|
||||||
|
// do something
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
if (response.data.length == 0) this.data_ended = true;
|
if (response.data.length == 0) this.data_ended = true;
|
||||||
else this.stream_data = this.stream_data.concat(response.data);
|
else this.stream_data = this.stream_data.concat(response.data);
|
||||||
this.loading = false;
|
this.loading = false;
|
||||||
} catch (e) {
|
|
||||||
// todo: handle better
|
|
||||||
this.errormsg = e.toString();
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
scroll() {
|
scroll() {
|
||||||
window.onscroll = () => {
|
window.onscroll = () => {
|
||||||
|
@ -79,8 +85,6 @@ export default {
|
||||||
<div class="row justify-content-md-center">
|
<div class="row justify-content-md-center">
|
||||||
<div class="col-xl-6 col-lg-9">
|
<div class="col-xl-6 col-lg-9">
|
||||||
|
|
||||||
<ErrorMsg v-if="errormsg" :msg="errormsg"></ErrorMsg>
|
|
||||||
|
|
||||||
<UserCard :user_id="requestedProfile" :name="user_data['name']" :followed="user_data['followed']"
|
<UserCard :user_id="requestedProfile" :name="user_data['name']" :followed="user_data['followed']"
|
||||||
:banned="user_data['banned']" :my_id="this.$currentSession" :show_new_post="true"
|
:banned="user_data['banned']" :my_id="this.$currentSession" :show_new_post="true"
|
||||||
@updateInfo="getMainData" @updatePosts="refresh" />
|
@updateInfo="getMainData" @updatePosts="refresh" />
|
||||||
|
@ -110,6 +114,7 @@ export default {
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<LoadingSpinner :loading="loading" /><br />
|
<LoadingSpinner :loading="loading" /><br />
|
||||||
|
<button v-if="loadingError" @click="refresh" class="btn btn-secondary w-100 py-3">Retry</button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
Loading…
Reference in a new issue