@@ -32,13 +32,11 @@ public FriendlyHttpResponseHandler(Context startContext) {
32
32
context = startContext ;
33
33
}
34
34
35
- @ Override
36
- public void onFailure (Throwable e ) {
37
- String errorDescription = "An unknown error occurred." ;
35
+ protected void alert (String msg ) {
38
36
AlertDialog .Builder builder = new AlertDialog .Builder (
39
37
context );
40
38
builder .setTitle ("Alert" );
41
- builder .setMessage (errorDescription );
39
+ builder .setMessage (msg );
42
40
builder .setPositiveButton ("OK" ,
43
41
new DialogInterface .OnClickListener () {
44
42
@ Override
@@ -50,6 +48,11 @@ public void onClick(DialogInterface dialog,
50
48
builder .create ().show ();
51
49
}
52
50
51
+ @ Override
52
+ public void onFailure (Throwable e ) {
53
+ alert ("An unknown error occurred." );
54
+ }
55
+
53
56
public void onFailure (Throwable e , JSONObject errorResponse ) {
54
57
String errorDescription = "An unknown error occurred." ;
55
58
try {
@@ -59,53 +62,16 @@ public void onFailure(Throwable e, JSONObject errorResponse) {
59
62
} catch (JSONException e1 ) {
60
63
e1 .printStackTrace ();
61
64
}
62
- AlertDialog .Builder builder = new AlertDialog .Builder (
63
- context );
64
- builder .setTitle ("Alert" );
65
- builder .setMessage (errorDescription );
66
- builder .setPositiveButton ("OK" ,
67
- new DialogInterface .OnClickListener () {
68
- @ Override
69
- public void onClick (DialogInterface dialog ,
70
- int which ) {
71
- dialog .dismiss ();
72
- }
73
- });
74
- builder .create ().show ();
65
+ alert (errorDescription );
75
66
}
76
67
77
68
@ Override
78
69
public void onFailure (Throwable e , String errorResponse ) {
79
- AlertDialog .Builder builder = new AlertDialog .Builder (
80
- context );
81
- builder .setTitle ("Alert" );
82
- builder .setMessage (errorResponse );
83
- builder .setPositiveButton ("OK" ,
84
- new DialogInterface .OnClickListener () {
85
- @ Override
86
- public void onClick (DialogInterface dialog ,
87
- int which ) {
88
- dialog .dismiss ();
89
- }
90
- });
91
- builder .create ().show ();
70
+ alert (errorResponse );
92
71
}
93
72
94
73
public void onFailure (Throwable e , JSONArray errorResponse ) {
95
- String errorDescription = "An unknown error occurred." ;
96
- AlertDialog .Builder builder = new AlertDialog .Builder (
97
- context );
98
- builder .setTitle ("Alert" );
99
- builder .setMessage (errorDescription );
100
- builder .setPositiveButton ("OK" ,
101
- new DialogInterface .OnClickListener () {
102
- @ Override
103
- public void onClick (DialogInterface dialog ,
104
- int which ) {
105
- dialog .dismiss ();
106
- }
107
- });
108
- builder .create ().show ();
74
+ alert ("An unknown error occurred." );
109
75
}
110
76
111
77
public void onSuccess (JSONObject response ) {
0 commit comments