Package com.foundationdb.server.error

Examples of com.foundationdb.server.error.ErrorCode


        if(!method.equals(HttpMethods.GET) && !method.equals(HttpMethods.POST) && !method.equals(HttpMethods.HEAD)) {
            return;
        }

        final String message;
        final ErrorCode error;
        final String note;
        if(response.getStatus() == HttpServletResponse.SC_NOT_FOUND) {
            message = "Path not found";
            if (!request.getRequestURI().contains("/v1/")) {
                note = "try including /v1/ in the path";
            } else {
                note = null;
            }
            error = ErrorCode.MALFORMED_REQUEST;
        } else {
            if (response instanceof Response) {
                note = ((Response)response).getReason();
            } else {
                note = null;
            }
            message = HttpStatus.getMessage(response.getStatus());
            error = ErrorCode.INTERNAL_ERROR;
        }

        response.setContentType(MediaType.APPLICATION_JSON);
        response.setHeader(HttpHeaders.CACHE_CONTROL, getCacheControl());

        StringBuilder builder = new StringBuilder();
        RestResponseBuilder.formatJsonError(builder, error.getFormattedValue(), message, note);
        builder.append('\n');

        response.setContentLength(builder.length());
        OutputStream out = response.getOutputStream();
        out.write(builder.toString().getBytes());
View Full Code Here


                        s = conn.createStatement();
                    }
                    s.execute(query);
                    break;
                } catch(SQLException e) {
                    ErrorCode code = ErrorCode.valueOfCode(e.getSQLState());
                    if(code == ErrorCode.STALE_STATEMENT) {
                        // retry with new statement
                        try {
                            s.close();
                        } catch(SQLException e1) {
                            // Ignore
                        }
                        s = null;
                    } else if(code.isRollbackClass()) {
                        // retry after slight delay
                        delay();
                    } else {
                        throw new RuntimeException(e);
                    }
View Full Code Here

        builder.append('\n');
        return builder.toString();
    }

    public WebApplicationException wrapException(Throwable e) {
        final ErrorCode code = ErrorCode.getCodeForRESTException(e);
        Response.Status status = EXCEPTION_STATUS_MAP.get(e.getClass());
        if(status == null) {
            status = Response.Status.CONFLICT;
        }
        code.logAtImportance(
                LOG, "Exception from request(method: {}, url: {}, params: {})",
                request.getMethod(), request.getRequestURL(), request.getQueryString(),
                e
        );
        String exMsg = (e.getMessage() != null) ? e.getMessage() : e.getClass().getName();
        return new WebApplicationException(
                Response.status(status)
                        .entity(formatErrorWithJsonp(code.getFormattedValue(), exMsg))
                        .type(isJsonp ? ResourceHelper.APPLICATION_JAVASCRIPT_TYPE : MediaType.APPLICATION_JSON_TYPE)
                        .build()
        );
    }
View Full Code Here

            Throwable throwable = ex;
            if (throwable instanceof Wrapper) {
                throwable = (SQLException)ex.getCause();
            }

            final ErrorCode code = ErrorCode.getCodeForRESTException(throwable);
            code.logAtImportance(
                    LOG, "Statement execution for query {} failed with exception {}", sql, throwable
            );

            throw JDBCException.throwUnwrapped(ex);
        }
View Full Code Here

    public static boolean isRollbackException(Throwable t) {
        if(t instanceof SQLException) {
            String sqlState = ((SQLException)t).getSQLState();
            try {
                ErrorCode code = ErrorCode.valueOfCode(sqlState);
                return code.isRollbackClass();
            } catch(IllegalArgumentException e) {
                // Not a valid SQLState
                return false;
            }
        }
View Full Code Here

TOP

Related Classes of com.foundationdb.server.error.ErrorCode

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.