From d3506f6a2ed4505bed92b646bc8c964608529f2e Mon Sep 17 00:00:00 2001 From: Uggla Date: Wed, 23 Sep 2015 23:52:58 +0200 Subject: [PATCH] Handle login exception. This is a first implementation that needs more elaborate error msg. --- redfish/exception.py | 15 ++++++++++----- redfish/main.py | 2 +- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/redfish/exception.py b/redfish/exception.py index f6f759a..6038480 100644 --- a/redfish/exception.py +++ b/redfish/exception.py @@ -1,5 +1,6 @@ # -*- coding: utf-8 -*- - +import sys +import config class RedfishException(Exception): """Base class for redfish exceptions""" @@ -8,9 +9,13 @@ class RedfishException(Exception): self.message = message - class AuthenticationFailureException(RedfishException): - pass - + def __init__(self, message=None, **kwargs): + super(AuthenticationFailureException, self).__init__(message=None, **kwargs) + config.logger.error(message) + # TODO + # Give a bit more details about the failure (check login etc...) + sys.exit(1) + class LogoutFailureException(RedfishException): - pass \ No newline at end of file + pass diff --git a/redfish/main.py b/redfish/main.py index 4f93db6..f7e6e5e 100644 --- a/redfish/main.py +++ b/redfish/main.py @@ -313,7 +313,7 @@ class RedfishConnection(object): # TODO : Manage exception with a class. # ======================================================================= if auth.status_code != 201: - pass + raise exception.AuthenticationFailureException("Login request return an invalid status code") #sysraise "Error getting token", auth.status_code self.connection_parameters.auth_token = auth.headers.get("x-auth-token")