use of com.box.androidsdk.content.models.BoxError in project box-android-sdk by box.
the class BoxException method getErrorType.
/**
* @return a known error type that corresponds to a given response and code.
*/
public ErrorType getErrorType() {
if (getCause() instanceof UnknownHostException) {
return ErrorType.NETWORK_ERROR;
}
BoxError error = this.getAsBoxError();
String errorString = error != null ? error.getError() : null;
return ErrorType.fromErrorInfo(errorString, getResponseCode());
}
use of com.box.androidsdk.content.models.BoxError in project box-android-sdk by box.
the class BoxException method getAsBoxError.
/**
* Gets the server response as a BoxError.
*
* @return the response as a BoxError, or null if the response cannot be converted.
*/
public BoxError getAsBoxError() {
try {
BoxError error = new BoxError();
error.createFromJson(getResponse());
return error;
} catch (Exception e) {
return null;
}
}
use of com.box.androidsdk.content.models.BoxError in project box-android-sdk by box.
the class MainActivity method uploadSampleFile.
/**
* Method demonstrates a sample file being uploaded using the file api
*/
private void uploadSampleFile() {
mDialog = ProgressDialog.show(MainActivity.this, getText(R.string.boxsdk_Please_wait), getText(R.string.boxsdk_Please_wait));
new Thread() {
@Override
public void run() {
try {
String uploadFileName = "box_logo.png";
InputStream uploadStream = getResources().getAssets().open(uploadFileName);
String destinationFolderId = "0";
String uploadName = "BoxSDKUpload.png";
BoxRequestsFile.UploadFile request = mFileApi.getUploadRequest(uploadStream, uploadName, destinationFolderId);
final BoxFile uploadFileInfo = request.send();
showToast("Uploaded " + uploadFileInfo.getName());
loadRootFolder();
} catch (IOException e) {
e.printStackTrace();
} catch (BoxException e) {
e.printStackTrace();
BoxError error = e.getAsBoxError();
if (error != null && error.getStatus() == HttpStatus.SC_CONFLICT) {
ArrayList<BoxEntity> conflicts = error.getContextInfo().getConflicts();
if (conflicts != null && conflicts.size() == 1 && conflicts.get(0) instanceof BoxFile) {
uploadNewVersion((BoxFile) conflicts.get(0));
return;
}
}
showToast("Upload failed");
} finally {
mDialog.dismiss();
}
}
}.start();
}
use of com.box.androidsdk.content.models.BoxError in project box-android-sdk by box.
the class OAuthActivity method getAuthFailure.
/**
* Takes an auth exception and converts it to an AuthFailure so it can be properly handled
*
* @param e The auth exception
* @return The typed AuthFailure
*/
private OAuthWebView.AuthFailure getAuthFailure(Exception e) {
String error = getString(R.string.boxsdk_Authentication_fail);
if (e != null) {
// Get the proper exception
Throwable ex = e instanceof ExecutionException ? ((ExecutionException) e).getCause() : e;
if (ex instanceof BoxException) {
BoxError boxError = ((BoxException) ex).getAsBoxError();
if (boxError != null) {
if (((BoxException) ex).getResponseCode() == HttpURLConnection.HTTP_FORBIDDEN || ((BoxException) ex).getResponseCode() == HttpURLConnection.HTTP_UNAUTHORIZED || boxError.getError().equals("unauthorized_device")) {
error += ":" + getResources().getText(R.string.boxsdk_Authentication_fail_forbidden) + "\n";
} else {
error += ":";
}
error += boxError.getErrorDescription();
return new OAuthWebView.AuthFailure(OAuthWebView.AuthFailure.TYPE_AUTHENTICATION_UNAUTHORIZED, error);
}
}
error += ":" + ex;
}
return new OAuthWebView.AuthFailure(OAuthWebView.AuthFailure.TYPE_GENERIC, error);
}
Aggregations