Search in sources :

Example 1 with ReadOnlyFileSystemException

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();
}
Also used : AccessDeniedException(java.nio.file.AccessDeniedException) FileAlreadyExistsException(java.nio.file.FileAlreadyExistsException) NotDirectoryException(java.nio.file.NotDirectoryException) NoSuchFileException(java.nio.file.NoSuchFileException) FileNotFoundException(java.io.FileNotFoundException) JsonObject(com.google.gson.JsonObject) DirectoryNotEmptyException(java.nio.file.DirectoryNotEmptyException) ReadOnlyFileSystemException(java.nio.file.ReadOnlyFileSystemException)

Aggregations

JsonObject (com.google.gson.JsonObject)1 FileNotFoundException (java.io.FileNotFoundException)1 AccessDeniedException (java.nio.file.AccessDeniedException)1 DirectoryNotEmptyException (java.nio.file.DirectoryNotEmptyException)1 FileAlreadyExistsException (java.nio.file.FileAlreadyExistsException)1 NoSuchFileException (java.nio.file.NoSuchFileException)1 NotDirectoryException (java.nio.file.NotDirectoryException)1 ReadOnlyFileSystemException (java.nio.file.ReadOnlyFileSystemException)1