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