Android Open Source - GOAC A P I Error






From Project

Back to project page GOAC.

License

The source code is released under:

MIT License

If you think the Android project GOAC listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

/*
 * Copyright 2010 University of Chicago//from  w  ww .j ava 2 s . c o m
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
 * either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.globusonline.transfer;

import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;

public class APIError extends Exception {
    public int statusCode;
    public String statusMessage;

    public String category;

    public String resource;
    public String requestId;
    public String code;
    public String message;

    public static final String CLIENT_ERROR = "ClientError";
    public static final String SERVER_ERROR = "ServerError";
    public static final String SERVICE_UNAVAILABLE = "ServiceUnavailable";
    public static final String EXTERNAL_ERROR = "ExternalError";
    public static final String UNKNOWN_ERROR = "UnknownError";

    public APIError(int statusCode, String statusMessage, String code) {
        this(statusCode, statusMessage, code, null, null, null);
    }

    public APIError(int statusCode, String statusMessage, String code,
                    String resource, String requestId, String message) {
        this.statusCode = statusCode;
        this.statusMessage = statusMessage;

        // Error category is the first part of the error code.
        if (code != null && code.length() > 0) {
            String[] codeParts = code.split(".", 2);
            this.category = codeParts[0];
        } else {
            this.category = "ServerError";
            code = "ServerError.UnknownError";
        }

        this.resource = resource;
        this.requestId = requestId;
        this.code = code;
        this.message = message;
    }

    /**
     * Fill the error fields from an XML DOM Document.
     */
    public void parseDocument(Document errorDocument) {
        NodeList nodes = errorDocument.getElementsByTagName("resource");
        if (nodes.getLength() > 0)
            resource = nodes.item(0).getFirstChild().getNodeValue();

        nodes = errorDocument.getElementsByTagName("request_id");
        if (nodes.getLength() > 0)
            requestId = nodes.item(0).getFirstChild().getNodeValue();

        nodes = errorDocument.getElementsByTagName("code");
        if (nodes.getLength() > 0)
            code = nodes.item(0).getFirstChild().getNodeValue();

        nodes = errorDocument.getElementsByTagName("message");
        if (nodes.getLength() > 0)
            message = nodes.item(0).getFirstChild().getNodeValue();
    }

    public String toString() {
        return code + "(" + statusCode + " "
               + statusMessage + ") on request '" + requestId
               + "' resource '" + resource + "': " + message;
    }
}




Java Source Code List

org.globus.globustransfer.EndpointActivity.java
org.globus.globustransfer.MainActivity.java
org.globus.globustransfer.MenuActivity.java
org.globus.globustransfer.MonitorActivity.java
org.globus.globustransfer.StartTransfer.java
org.globusonline.transfer.APIError.java
org.globusonline.transfer.BCTransferAPIClient.java
org.globusonline.transfer.BaseTransferAPIClient.java
org.globusonline.transfer.JSONTransferAPIClient.java
org.json.JSONArray.java
org.json.JSONException.java
org.json.JSONObject.java
org.json.JSONString.java
org.json.JSONTokener.java