解决token 401问题
This commit is contained in:
@ -78,26 +78,34 @@ public class CropImageActivity extends BaseActivity {
|
||||
// 上传图片
|
||||
JSONObject result = FileUtils.uploadFile(Config.USER_HOST + "icon",
|
||||
path, TokenUtils.getToken(CropImageActivity.this));
|
||||
dialog.dismiss();
|
||||
if (result != null) {
|
||||
try {
|
||||
int statusCode = result.getInt("statusCode");
|
||||
if (statusCode == HttpURLConnection.HTTP_OK) {
|
||||
Intent data = new Intent();
|
||||
data.putExtra("url", result.getString("icon"));
|
||||
setResult(RESULT_OK, data);
|
||||
finish();
|
||||
handler.sendEmptyMessage(0);
|
||||
} else if (statusCode == HttpURLConnection.HTTP_FORBIDDEN
|
||||
&& "too frequent".equals(result.getString("detail"))) {
|
||||
handler.sendEmptyMessage(2);
|
||||
}
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
try {
|
||||
if (result != null && result.getInt("statusCode") == 401) {
|
||||
result = FileUtils.uploadFile(Config.USER_HOST + "icon",
|
||||
path, TokenUtils.getToken(CropImageActivity.this, false));
|
||||
}
|
||||
} else {
|
||||
handler.sendEmptyMessage(1);
|
||||
if (result != null) {
|
||||
try {
|
||||
int statusCode = result.getInt("statusCode");
|
||||
if (statusCode == HttpURLConnection.HTTP_OK) {
|
||||
Intent data = new Intent();
|
||||
data.putExtra("url", result.getString("icon"));
|
||||
setResult(RESULT_OK, data);
|
||||
finish();
|
||||
handler.sendEmptyMessage(0);
|
||||
} else if (statusCode == HttpURLConnection.HTTP_FORBIDDEN
|
||||
&& "too frequent".equals(result.getString("detail"))) {
|
||||
handler.sendEmptyMessage(2);
|
||||
}
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
} else {
|
||||
handler.sendEmptyMessage(1);
|
||||
}
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
dialog.dismiss();
|
||||
} else {
|
||||
dialog.dismiss();
|
||||
handler.sendEmptyMessage(1);
|
||||
|
||||
Reference in New Issue
Block a user