handle invalid auth token resolve #52
This commit is contained in:
parent
a4b71c1707
commit
e55fafe04b
1 changed files with 32 additions and 17 deletions
|
@ -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 => {
|
||||
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);
|
||||
}).catch(err => {
|
||||
console.log(err);
|
||||
}
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -204,22 +211,28 @@ export class StreamPage {
|
|||
|
||||
fetchThread(threadid) {
|
||||
pnut.thread(threadid, {include_deleted: 0, include_raw: 1, count: 140}).then(res => {
|
||||
if (res.meta.code === 401) {
|
||||
this.storage.clear();
|
||||
this.navCtrl.setRoot(LoginPage);
|
||||
} else {
|
||||
this.navCtrl.push(ThreadPage, {posts: res.data, me: this.myUsername});
|
||||
}).catch(err => {
|
||||
console.log(err);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
fetchMyPosts() {
|
||||
console.log('-- fetching mentions --');
|
||||
this.fetcher('me', {include_raw: 1, count: 40}).then(res => {
|
||||
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);
|
||||
}).catch(err => {
|
||||
console.log(err);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -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 => {
|
||||
|
|
Reference in a new issue