Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
 package com.robrua.orianna.api;

Encapsulates all common error conditions from the API

Author(s):
Rob Rua (FatalElement - NA) (robrua@alumni.cmu.edu)
 
 public class APIException extends RuntimeException {
     public static enum Type {
        BAD_REQUEST, DATA_NOT_FOUND, PARSE_FAILURE, RATE_LIMITED, SERVER_ERROR, UNAUTHORIZED, UNAVAILABLE, UNKNOWN;
    }
    private static final long serialVersionUID = 5015141496105277138L;
    private static String getMessage(final Type type) {
        switch(type) {
            case :
                return "Bad request";
            case :
                return "Requested data not found";
            case :
                return "Failed to parse Riot's JSON response";
            case :
                return "Rate limit exceeded";
            case :
                return "Internal server error";
            case :
                return "Unauthorized";
            case :
                return "Service unavailable";
            case :
                return "An unknown API error occured";
            default:
                return "An unknown API error occured";
        }
    }
    public final Exception cause;
    public final Type type;

    

Parameters:
type the type of error that occurred
cause the Exception that was thrown
    public APIException(final Type typefinal Exception cause) {
        super(getMessage(type));
        this. = type;
        this. = cause;
    }

    

Parameters:
type the type of error that occurred
URL the URL that was accessed when the Exception was thrown
cause the Exception that was thrown
    public APIException(final Type typefinal String URLfinal Exception cause) {
        super(getMessage(type) + " for request: " + URL);
        this. = type;
        this. = cause;
    }
New to GrepCode? Check out our FAQ X