handle invalid auth token resolve #52

This commit is contained in:
Morgan McMillian 2018-02-19 18:35:21 -08:00
parent a4b71c1707
commit e55fafe04b

View file

@ -6,6 +6,7 @@ import { FileChooser } from '@ionic-native/file-chooser';
import { FilePath } from '@ionic-native/file-path';
import { FileTransfer, FileUploadOptions, FileTransferObject } from '@ionic-native/file-transfer';
import { Events } from 'ionic-angular';
import { LoginPage } from '../login/login';
import * as pnut from 'pnut-butter';
@ -166,13 +167,19 @@ export class StreamPage {
count: 40
};
this.fetcher(params).then(res => {
this.posts = this.parseData(res.data);
this.since_id = res.meta.max_id;
this.before_id = res.meta.min_id;
console.log('since_id: ' + this.since_id);
console.log('before_id: ' + this.before_id);
}).catch(err => {
console.log(err);
console.log('-fetch success-');
console.log(JSON.stringify(res));
if (res.meta.code === 401) {
this.storage.clear();
this.navCtrl.setRoot(LoginPage);
} else {
this.posts = this.parseData(res.data);
this.since_id = res.meta.max_id;
this.before_id = res.meta.min_id;
console.log('since_id: ' + this.since_id);
console.log('before_id: ' + this.before_id);
}
});
}
@ -204,22 +211,28 @@ export class StreamPage {
fetchThread(threadid) {
pnut.thread(threadid, {include_deleted: 0, include_raw: 1, count: 140}).then(res => {
this.navCtrl.push(ThreadPage, {posts: res.data, me: this.myUsername});
}).catch(err => {
console.log(err);
if (res.meta.code === 401) {
this.storage.clear();
this.navCtrl.setRoot(LoginPage);
} else {
this.navCtrl.push(ThreadPage, {posts: res.data, me: this.myUsername});
}
});
}
fetchMyPosts() {
console.log('-- fetching mentions --');
this.fetcher('me', {include_raw: 1, count: 40}).then(res => {
this.posts = res.data;
this.since_id = res.meta.max_id;
this.before_id = res.meta.min_id;
console.log('since_id: ' + this.since_id);
console.log('before_id: ' + this.before_id);
}).catch(err => {
console.log(err);
if (res.meta.code === 401) {
this.storage.clear();
this.navCtrl.setRoot(LoginPage);
} else {
this.posts = res.data;
this.since_id = res.meta.max_id;
this.before_id = res.meta.min_id;
console.log('since_id: ' + this.since_id);
console.log('before_id: ' + this.before_id);
}
});
}
@ -529,6 +542,8 @@ export class NewPostModal {
console.log('-create file error-');
console.log(JSON.stringify(err));
console.log('-create file error-');
let edata = JSON.parse(err.body);
this.presentToast(edata.meta.error_message);
});
}).catch(err => {