mirror of
https://git.victorphan.net/basketballcantho/Teedy_custom.git
synced 2026-08-05 22:03:11 +07:00
Closes #20: Clean error message if document or file does not exist
This commit is contained in:
@@ -9,6 +9,7 @@ import javax.ws.rs.Produces;
|
||||
import javax.ws.rs.QueryParam;
|
||||
import javax.ws.rs.core.MediaType;
|
||||
import javax.ws.rs.core.Response;
|
||||
import javax.ws.rs.core.Response.Status;
|
||||
|
||||
import org.codehaus.jettison.json.JSONException;
|
||||
import org.codehaus.jettison.json.JSONObject;
|
||||
@@ -55,7 +56,7 @@ public class AuditLogResource extends BaseResource {
|
||||
// Check ACL on the document
|
||||
AclDao aclDao = new AclDao();
|
||||
if (!aclDao.checkPermission(documentId, PermType.READ, principal.getId())) {
|
||||
throw new ForbiddenClientException();
|
||||
return Response.status(Status.NOT_FOUND).build();
|
||||
}
|
||||
criteria.setDocumentId(documentId);
|
||||
}
|
||||
|
||||
@@ -20,6 +20,7 @@ import javax.ws.rs.Produces;
|
||||
import javax.ws.rs.QueryParam;
|
||||
import javax.ws.rs.core.MediaType;
|
||||
import javax.ws.rs.core.Response;
|
||||
import javax.ws.rs.core.Response.Status;
|
||||
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.codehaus.jettison.json.JSONException;
|
||||
@@ -92,7 +93,7 @@ public class DocumentResource extends BaseResource {
|
||||
throw new ForbiddenClientException();
|
||||
}
|
||||
} catch (NoResultException e) {
|
||||
throw new ClientException("DocumentNotFound", MessageFormat.format("Document not found: {0}", documentId));
|
||||
return Response.status(Status.NOT_FOUND).build();
|
||||
}
|
||||
|
||||
JSONObject document = new JSONObject();
|
||||
@@ -430,7 +431,7 @@ public class DocumentResource extends BaseResource {
|
||||
try {
|
||||
document = documentDao.getDocument(id, PermType.WRITE, principal.getId());
|
||||
} catch (NoResultException e) {
|
||||
throw new ClientException("DocumentNotFound", MessageFormat.format("Document not found: {0}", id));
|
||||
return Response.status(Status.NOT_FOUND).build();
|
||||
}
|
||||
|
||||
// Update the document
|
||||
@@ -514,7 +515,7 @@ public class DocumentResource extends BaseResource {
|
||||
document = documentDao.getDocument(id, PermType.WRITE, principal.getId());
|
||||
fileList = fileDao.getByDocumentId(principal.getId(), id);
|
||||
} catch (NoResultException e) {
|
||||
throw new ClientException("DocumentNotFound", MessageFormat.format("Document not found: {0}", id));
|
||||
return Response.status(Status.NOT_FOUND).build();
|
||||
}
|
||||
|
||||
// Delete the document
|
||||
|
||||
@@ -102,7 +102,7 @@ public class FileResource extends BaseResource {
|
||||
try {
|
||||
document = documentDao.getDocument(documentId, PermType.WRITE, principal.getId());
|
||||
} catch (NoResultException e) {
|
||||
throw new ClientException("DocumentNotFound", MessageFormat.format("Document not found: {0}", documentId));
|
||||
return Response.status(Status.NOT_FOUND).build();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -199,7 +199,7 @@ public class FileResource extends BaseResource {
|
||||
file = fileDao.getFile(id, principal.getId());
|
||||
document = documentDao.getDocument(documentId, PermType.WRITE, principal.getId());
|
||||
} catch (NoResultException e) {
|
||||
throw new ClientException("DocumentNotFound", MessageFormat.format("Document not found: {0}", documentId));
|
||||
return Response.status(Status.NOT_FOUND).build();
|
||||
}
|
||||
|
||||
// Check that the file is orphan
|
||||
@@ -259,7 +259,7 @@ public class FileResource extends BaseResource {
|
||||
try {
|
||||
documentDao.getDocument(documentId, PermType.WRITE, principal.getId());
|
||||
} catch (NoResultException e) {
|
||||
throw new ClientException("DocumentNotFound", MessageFormat.format("Document not found: {0}", documentId));
|
||||
return Response.status(Status.NOT_FOUND).build();
|
||||
}
|
||||
|
||||
// Reorder files
|
||||
@@ -295,13 +295,9 @@ public class FileResource extends BaseResource {
|
||||
|
||||
// Check document visibility
|
||||
if (documentId != null) {
|
||||
try {
|
||||
AclDao aclDao = new AclDao();
|
||||
if (!aclDao.checkPermission(documentId, PermType.READ, shareId == null ? principal.getId() : shareId)) {
|
||||
throw new ForbiddenClientException();
|
||||
}
|
||||
} catch (NoResultException e) {
|
||||
throw new ClientException("DocumentNotFound", MessageFormat.format("Document not found: {0}", documentId));
|
||||
AclDao aclDao = new AclDao();
|
||||
if (!aclDao.checkPermission(documentId, PermType.READ, shareId == null ? principal.getId() : shareId)) {
|
||||
return Response.status(Status.NOT_FOUND).build();
|
||||
}
|
||||
} else if (!authenticated) {
|
||||
throw new ForbiddenClientException();
|
||||
@@ -358,7 +354,7 @@ public class FileResource extends BaseResource {
|
||||
documentDao.getDocument(file.getDocumentId(), PermType.WRITE, principal.getId());
|
||||
}
|
||||
} catch (NoResultException e) {
|
||||
throw new ClientException("FileNotFound", MessageFormat.format("File not found: {0}", id));
|
||||
return Response.status(Status.NOT_FOUND).build();
|
||||
}
|
||||
|
||||
// Delete the file
|
||||
@@ -498,7 +494,7 @@ public class FileResource extends BaseResource {
|
||||
throw new ForbiddenClientException();
|
||||
}
|
||||
} catch (NoResultException e) {
|
||||
throw new ClientException("DocumentNotFound", MessageFormat.format("Document not found: {0}", documentId));
|
||||
return Response.status(Status.NOT_FOUND).build();
|
||||
}
|
||||
|
||||
// Get files and user associated with this document
|
||||
|
||||
Reference in New Issue
Block a user