Skip to content
This repository has been archived by the owner on Nov 9, 2017. It is now read-only.

Commit

Permalink
improve error messages for failed rest file upload
Browse files Browse the repository at this point in the history
  • Loading branch information
davidmason committed Sep 18, 2012
1 parent 84be005 commit 19dd3d5
Showing 1 changed file with 22 additions and 7 deletions.
29 changes: 22 additions & 7 deletions zanata-war/src/main/java/org/zanata/rest/service/FileService.java
Expand Up @@ -148,7 +148,7 @@ public Response uploadSourceFile( @PathParam("projectSlug") String projectSlug,
if (!isDocumentUploadAllowed(projectSlug, iterationSlug))
{
return Response.status(Status.FORBIDDEN)
.entity("You do not have permission to upload source documents for this project-version\n")
.entity("You do not have permission to upload source documents to project-version \"" + projectSlug + ":" + iterationSlug + "\".\n")
.build();
}

Expand Down Expand Up @@ -266,6 +266,7 @@ private Response checkUploadPreconditions(String projectSlug, String iterationSl
.entity("Valid combination of username and api-key for this server were not included in the request\n")
.build();
}

if (docId == null || docId.length() == 0)
{
return Response.status(Status.PRECONDITION_FAILED)
Expand Down Expand Up @@ -299,9 +300,24 @@ private Response checkUploadPreconditions(String projectSlug, String iterationSl
if (projectIteration == null)
{
return Response.status(Status.NOT_FOUND)
.entity("The specified project-version does not exist on this server.")
.entity("The specified project-version \"" + projectSlug + ":" + iterationSlug + "\" does not exist on this server.\n")
.build();
}

if (projectIteration.getProject().getStatus() != EntityStatus.ACTIVE)
{
return Response.status(Status.FORBIDDEN)
.entity("The project \"" + projectSlug + "\" is not active. Document upload is not allowed.\n")
.build();
}

if (projectIteration.getStatus() != EntityStatus.ACTIVE)
{
return Response.status(Status.FORBIDDEN)
.entity("The project-version \"" + projectSlug + ":" + iterationSlug + "\" is not active. Document upload is not allowed.\n")
.build();
}

return null;
}

Expand Down Expand Up @@ -377,21 +393,22 @@ public Response uploadTranslationFile( @PathParam("projectSlug") String projectS
if (localeId == null)
{
return Response.status(Status.NOT_FOUND)
.entity("The specified locale does not exist on this server\n")
.entity("The specified locale \"" + locale + "\" does not exist on this server.\n")
.build();
}

if (!isTranslationUploadAllowed(projectSlug, iterationSlug, localeId))
{
return Response.status(Status.FORBIDDEN)
.entity("You do not have permission to upload translations for the specified locale to this project-version\n")
.entity("You do not have permission to upload translations for locale \"" + locale
+ "\" to project-version \"" + projectSlug + ":" + iterationSlug + "\".\n")
.build();
}

if (documentDAO.getByProjectIterationAndDocId(projectSlug, iterationSlug, docId) == null)
{
return Response.status(Status.NOT_FOUND)
.entity("No document with the specified id exists in this project-version\n")
.entity("No document with id \"" + docId + "\" exists in project-version \"" + projectSlug + ":" + iterationSlug + "\".\n")
.build();
}

Expand All @@ -412,12 +429,10 @@ public Response uploadTranslationFile( @PathParam("projectSlug") String projectS
MergeType mergeType;
if ("import".equals(merge))
{
log.info("merge type import");
mergeType = MergeType.IMPORT;
}
else
{
log.info("merge type: " + merge);
mergeType = MergeType.AUTO;
}

Expand Down

0 comments on commit 19dd3d5

Please sign in to comment.