use of java.nio.file.ReadOnlyFileSystemException in project ballerina by ballerina-lang.
the class FileSystemService method createErrorResponse.
/**
* Creates an error response for the given IO Exception.
*
* @param ex Thrown Exception
* @return Error Message
*/
private Response createErrorResponse(Throwable ex) {
JsonObject entity = new JsonObject();
String errMsg = ex.getMessage();
if (ex instanceof AccessDeniedException) {
errMsg = "Access Denied to " + ex.getMessage();
} else if (ex instanceof NoSuchFileException) {
errMsg = "No such file: " + ex.getMessage();
} else if (ex instanceof FileAlreadyExistsException) {
errMsg = "File already exists: " + ex.getMessage();
} else if (ex instanceof NotDirectoryException) {
errMsg = "Not a directory: " + ex.getMessage();
} else if (ex instanceof ReadOnlyFileSystemException) {
errMsg = "Read only: " + ex.getMessage();
} else if (ex instanceof DirectoryNotEmptyException) {
errMsg = "Directory not empty: " + ex.getMessage();
} else if (ex instanceof FileNotFoundException) {
errMsg = "File not found: " + ex.getMessage();
}
entity.addProperty("Error", errMsg);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(entity).header(ACCESS_CONTROL_ALLOW_ORIGIN_HEADER, '*').type(MediaType.APPLICATION_JSON).build();
}
Aggregations