use of com.dropbox.core.v2.files.LookupError in project dropbox-sdk-java by dropbox.
the class DropboxBrowse method doBrowse.
// -------------------------------------------------------------------------------------------
// GET /browse?path=...
// -------------------------------------------------------------------------------------------
// The page that lets you browse your Dropbox account. Makes Dropbox API calls to figure out
// the contents of your files and folders and display them to you.
public void doBrowse(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
if (!common.checkGet(request, response))
return;
User user = common.getLoggedInUser(request);
if (user == null) {
common.pageSoftError(response, "Can't do /browse. Nobody is logged in.");
return;
}
DbxClientV2 dbxClient = requireDbxClient(request, response, user);
if (dbxClient == null)
return;
String path = request.getParameter("path");
if (path == null || path.length() == 0) {
renderFolder(response, user, dbxClient, "");
} else {
String pathError = DbxPathV2.findError(path);
if (pathError != null) {
response.sendError(400, "Invalid path: " + jq(path) + ": " + pathError);
return;
}
Metadata metadata;
try {
metadata = dbxClient.files().getMetadata(path);
} catch (GetMetadataErrorException ex) {
if (ex.errorValue.isPath()) {
LookupError le = ex.errorValue.getPathValue();
if (le.isNotFound()) {
response.sendError(400, "Path doesn't exist on Dropbox: " + jq(path));
return;
}
}
common.handleException(response, ex, "getMetadata(" + jq(path) + ")");
return;
} catch (DbxException ex) {
common.handleDbxException(response, user, ex, "getMetadata(" + jq(path) + ")");
return;
}
path = DbxPathV2.getParent(path) + "/" + metadata.getName();
if (metadata instanceof FolderMetadata) {
renderFolder(response, user, dbxClient, path);
} else {
renderFile(response, path, (FileMetadata) metadata);
}
}
}
use of com.dropbox.core.v2.files.LookupError in project dropbox-sdk-java by dropbox.
the class DbxClientV2IT method testError409.
@Test(expectedExceptions = { GetMetadataErrorException.class })
public void testError409() throws Exception {
DbxClientV2 client = ITUtil.newClientV2();
String path = ITUtil.path(getClass(), "/testError409/" + ITUtil.format(new Date()));
try {
client.files().getMetadata(path);
} catch (GetMetadataErrorException ex) {
assertThat(ex.getRequestId()).isNotNull();
if (ex.getUserMessage() != null) {
assertThat(ex.getUserMessage().getLocale()).isNotNull();
assertThat(ex.getUserMessage().getText()).isNotNull();
assertThat(ex.getUserMessage().toString()).isNotNull();
}
GetMetadataError err = ex.errorValue;
assertThat(err).isNotNull();
assertThat(err.tag()).isEqualTo(GetMetadataError.Tag.PATH);
assertThat(err.isPath()).isTrue();
LookupError lookup = err.getPathValue();
assertThat(lookup).isNotNull();
assertThat(lookup.tag()).isEqualTo(LookupError.Tag.NOT_FOUND);
assertThat(lookup.isNotFound()).isTrue();
assertThat(lookup.isNotFile()).isFalse();
assertThat(lookup.isOther()).isFalse();
assertThat(lookup.isMalformedPath()).isFalse();
// raise so test can confirm an exception was thrown
throw ex;
}
}
Aggregations