Skip to content

Commit 1022ca8

Browse files
committed
feat(components): fix retry request state error
1 parent 22f95e5 commit 1022ca8

File tree

2 files changed

+14
-24
lines changed

2 files changed

+14
-24
lines changed

src/components/request.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,17 @@ export class Request {
3333
};
3434
this.requestOptions = Object.assign(
3535
{},
36-
{ pluginsOptions },
36+
{ pluginsOptions, retry: true },
3737
this.options
3838
);
3939

4040
this.request();
41+
42+
if (this.error) {
43+
this.error.retry.subscribe(() => {
44+
this.request();
45+
});
46+
}
4147
}
4248

4349
request() {
@@ -60,10 +66,6 @@ export class Request {
6066

6167
if (this.error) {
6268

63-
if (!this.error.idRetry) {
64-
this.error.idRetry = this.url;
65-
}
66-
6769
if (!this.error.error) {
6870
this.error.error = error;
6971
}

src/components/states.ts

Lines changed: 7 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { Component, Input, Optional } from '@angular/core';
22
import { ViewController } from 'ionic-angular';
3-
import { Http } from '@ramonornela/http';
3+
import { Subject } from 'rxjs/Subject';
44

55
@Component({
66
selector: 'loading',
@@ -66,7 +66,7 @@ export class StateEmpty {
6666
selector: 'error',
6767
template: `
6868
<div *ngIf="enabled">
69-
<span class="msg-exception">{{msgException}}</span>
69+
<span class="msg-exception">{{messageException}}</span>
7070
<button ion-button (click)="retryRequest()">
7171
<span>
7272
<ng-content></ng-content>
@@ -78,34 +78,22 @@ export class StateEmpty {
7878
export class StateError {
7979
enabled: boolean = false;
8080

81-
private id: string;
82-
83-
private msgException;
84-
8581
@Input() messageRetry: string = 'Tentar novamente';
8682

8783
@Input() messageCallback: Function;
8884

8985
@Input() error: any;
9086

91-
constructor(private http: Http) {}
87+
@Input() messageException: string;
9288

93-
@Input()
94-
set messageException(message: string) {
95-
this.msgException = message;
96-
}
97-
98-
@Input()
99-
set idRetry(id: string) {
100-
this.id = id;
101-
}
89+
retry = new Subject<StateError>();
10290

10391
retryRequest() {
104-
this.http.retryRequest(this.id);
92+
this.retry.next(this);
10593
}
10694

10795
present() {
108-
if (!this.msgException) {
96+
if (!this.messageException) {
10997
if (!this.error) {
11098
throw new Error('Error is required!');
11199
}
@@ -114,7 +102,7 @@ export class StateError {
114102
let messageError = this.messageCallback;
115103
throw new Error(`${messageError} is not function`);
116104
}
117-
this.msgException = this.messageCallback.call(null, this.error);
105+
this.messageException = this.messageCallback.call(null, this.error);
118106
}
119107

120108
this.enabled = true;

0 commit comments

Comments
 (0)