From cdea2d210d07eb14d7a04a2b45a739bd5b0d025d Mon Sep 17 00:00:00 2001 From: alena Date: Mon, 22 Nov 2010 10:13:27 -0800 Subject: [PATCH] Better logging for api exceptions. --- server/src/com/cloud/api/ApiDispatcher.java | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/server/src/com/cloud/api/ApiDispatcher.java b/server/src/com/cloud/api/ApiDispatcher.java index 92971f35560..656bedf7cfb 100644 --- a/server/src/com/cloud/api/ApiDispatcher.java +++ b/server/src/com/cloud/api/ApiDispatcher.java @@ -68,22 +68,30 @@ public class ApiDispatcher { cmd.callCreate(); } catch (Throwable t) { if (t instanceof InvalidParameterValueException || t instanceof IllegalArgumentException) { + s_logger.info(t); throw new ServerApiException(BaseCmd.PARAM_ERROR, t.getMessage()); }else if (t instanceof PermissionDeniedException) { + s_logger.info(t); throw new ServerApiException(BaseCmd.ACCOUNT_ERROR, t.getMessage()); }else if (t instanceof AccountLimitException) { + s_logger.info(t); throw new ServerApiException(BaseCmd.ACCOUNT_RESOURCE_LIMIT_ERROR, t.getMessage()); }else if (t instanceof InsufficientCapacityException) { + s_logger.info(t); throw new ServerApiException(BaseCmd.INSUFFICIENT_CAPACITY_ERROR, t.getMessage()); }else if (t instanceof ResourceAllocationException) { + s_logger.info(t); throw new ServerApiException(BaseCmd.RESOURCE_ALLOCATION_ERROR, t.getMessage()); }else if (t instanceof ResourceUnavailableException) { + s_logger.warn(t); throw new ServerApiException(BaseCmd.RESOURCE_UNAVAILABLE_ERROR, t.getMessage()); }else if (t instanceof ServerApiException) { + s_logger.warn(t); throw new ServerApiException(((ServerApiException) t).getErrorCode(), ((ServerApiException) t).getDescription()); }else if (t instanceof AsyncCommandQueued) { throw (AsyncCommandQueued)t; }else { + s_logger.warn(t); s_logger.error("Exception while executing " + cmd.getClass().getSimpleName() + ":", t); if (UserContext.current().getAccount() == null || UserContext.current().getAccount().getType() == Account.ACCOUNT_TYPE_ADMIN) throw new ServerApiException(BaseCmd.INTERNAL_ERROR, t.getMessage()); @@ -99,22 +107,30 @@ public class ApiDispatcher { cmd.execute(); } catch (Throwable t) { if (t instanceof InvalidParameterValueException || t instanceof IllegalArgumentException) { + s_logger.info(t); throw new ServerApiException(BaseCmd.PARAM_ERROR, t.getMessage()); }else if (t instanceof PermissionDeniedException) { + s_logger.info(t); throw new ServerApiException(BaseCmd.ACCOUNT_ERROR, t.getMessage()); }else if (t instanceof AccountLimitException) { + s_logger.info(t); throw new ServerApiException(BaseCmd.ACCOUNT_RESOURCE_LIMIT_ERROR, t.getMessage()); }else if (t instanceof InsufficientCapacityException) { + s_logger.info(t); throw new ServerApiException(BaseCmd.INSUFFICIENT_CAPACITY_ERROR, t.getMessage()); }else if (t instanceof ResourceAllocationException) { + s_logger.warn(t); throw new ServerApiException(BaseCmd.RESOURCE_ALLOCATION_ERROR, t.getMessage()); }else if (t instanceof ResourceUnavailableException) { + s_logger.warn(t); throw new ServerApiException(BaseCmd.RESOURCE_UNAVAILABLE_ERROR, t.getMessage()); }else if (t instanceof ServerApiException) { + s_logger.warn(t); throw new ServerApiException(((ServerApiException) t).getErrorCode(), ((ServerApiException) t).getDescription()); } else if (t instanceof AsyncCommandQueued) { throw (AsyncCommandQueued)t; }else { + s_logger.warn(t); s_logger.error("Exception while executing " + cmd.getClass().getSimpleName() + ":", t); if (UserContext.current().getAccount() == null || UserContext.current().getAccount().getType() == Account.ACCOUNT_TYPE_ADMIN) throw new ServerApiException(BaseCmd.INTERNAL_ERROR, t.getMessage());