Search in sources :

Example 1 with ErrorView

use of org.ow2.proactive_grid_cloud_portal.cli.json.ErrorView in project scheduling by ow2-proactive.

the class AbstractCommand method buildCLIException.

protected CLIException buildCLIException(int reason, HttpResponseWrapper response, ApplicationContext currentContext) {
    String responseContent = StringUtility.responseAsString(response);
    ErrorView errorView = errorView(responseContent, currentContext);
    if (errorView != null) {
        throw new CLIException(reason, errorView.getErrorMessage(), errorView.getStackTrace());
    } else {
        HttpErrorView httpErrorView = errorView(responseContent);
        throw new CLIException(reason, httpErrorView.errorMessage, httpErrorView.stackTrace);
    }
}
Also used : CLIException(org.ow2.proactive_grid_cloud_portal.cli.CLIException) ErrorView(org.ow2.proactive_grid_cloud_portal.cli.json.ErrorView) Throwables.getStackTraceAsString(com.google.common.base.Throwables.getStackTraceAsString)

Example 2 with ErrorView

use of org.ow2.proactive_grid_cloud_portal.cli.json.ErrorView in project scheduling by ow2-proactive.

the class AbstractCommand method handleError.

@SuppressWarnings("unchecked")
protected void handleError(String errorMessage, HttpResponseWrapper response, ApplicationContext currentContext) {
    String responseContent = StringUtility.responseAsString(response);
    Stack resultStack = resultStack(currentContext);
    ErrorView errorView = errorView(responseContent, currentContext);
    if (errorView != null) {
        resultStack.push(errorView);
    } else {
        resultStack.push(responseContent);
    }
    if (errorView != null) {
        writeError(errorMessage, errorView, currentContext);
    } else {
        writeError(errorMessage, responseContent, currentContext);
    }
}
Also used : ErrorView(org.ow2.proactive_grid_cloud_portal.cli.json.ErrorView) Throwables.getStackTraceAsString(com.google.common.base.Throwables.getStackTraceAsString) Stack(java.util.Stack)

Example 3 with ErrorView

use of org.ow2.proactive_grid_cloud_portal.cli.json.ErrorView in project scheduling by ow2-proactive.

the class AbstractCommand method errorView.

protected HttpErrorView errorView(String responseContent) {
    try {
        HttpErrorView errorView = new HttpErrorView();
        BufferedReader reader = new BufferedReader(new StringReader(responseContent));
        String line;
        while ((line = reader.readLine()) != null) {
            if (line.startsWith("errorMessage:")) {
                errorView.errorMessage = line.substring(line.indexOf(':')).trim();
                break;
            }
        }
        while ((line = reader.readLine()) != null) {
            if (line.startsWith("httpErrorCode:")) {
                errorView.errorCode = line.substring(line.indexOf(':')).trim();
                break;
            }
        }
        while ((line = reader.readLine()) != null) {
            if (line.startsWith("stackTrace:")) {
                StringBuilder buffer = new StringBuilder();
                while ((line = reader.readLine()) != null) {
                    buffer.append(line);
                }
                errorView.stackTrace = buffer.toString();
                break;
            }
        }
        return errorView;
    } catch (IOException ioe) {
        throw new CLIException(REASON_IO_ERROR, ioe);
    }
}
Also used : BufferedReader(java.io.BufferedReader) StringReader(java.io.StringReader) CLIException(org.ow2.proactive_grid_cloud_portal.cli.CLIException) Throwables.getStackTraceAsString(com.google.common.base.Throwables.getStackTraceAsString) IOException(java.io.IOException)

Aggregations

Throwables.getStackTraceAsString (com.google.common.base.Throwables.getStackTraceAsString)3 CLIException (org.ow2.proactive_grid_cloud_portal.cli.CLIException)2 ErrorView (org.ow2.proactive_grid_cloud_portal.cli.json.ErrorView)2 BufferedReader (java.io.BufferedReader)1 IOException (java.io.IOException)1 StringReader (java.io.StringReader)1 Stack (java.util.Stack)1