<s> import json <EOL> class MisfitException ( Exception ) : <EOL> pass <EOL> class MisfitHttpException ( MisfitException ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , code , message , response = None ) : <EOL> self . code = code <EOL> self . message = message <EOL> self . response = response <EOL> super ( MisfitHttpException , self ) . __init__ ( self , message ) <EOL> @ staticmethod <EOL> def build_exception ( exc ) : <EOL> code = exc . response . status_code if hasattr ( exc , '<STR_LIT>' ) else <NUM_LIT> <EOL> message = exc . message if hasattr ( exc , '<STR_LIT:message>' ) else '<STR_LIT>' <EOL> try : <EOL> json_content = json . loads ( exc . content ) <EOL> except ValueError : <EOL> pass <EOL> else : <EOL> if '<STR_LIT:message>' in json_content : <EOL> message = json_content [ '<STR_LIT:message>' ] <EOL> elif '<STR_LIT>' in json_content : <EOL> message = json_content [ '<STR_LIT>' ] <EOL> if '<STR_LIT:code>' in json_content : <EOL> code = json_content [ '<STR_LIT:code>' ] <EOL> elif '<STR_LIT>' in json_content : <EOL> code = json_content [ '<STR_LIT>' ] <EOL> exceptions = { <EOL> <NUM_LIT> : MisfitBadRequest , <EOL> <NUM_LIT> : MisfitUnauthorized , <EOL> <NUM_LIT> : MisfitForbidden , <EOL> <NUM_LIT> : MisfitNotFoundError , <EOL> <NUM_LIT> : MisfitRateLimitError , <EOL> <NUM_LIT> : MisfitUnknownError , <EOL> <NUM_LIT> : MisfitBadGateway <EOL> } <EOL> raise exceptions [ code ] ( code , message , getattr ( exc , '<STR_LIT>' , None ) ) <EOL> class MisfitNotFoundError ( MisfitHttpException ) : <EOL> pass <EOL> class MisfitBadRequest ( MisfitHttpException ) : <EOL> pass <EOL> class MisfitBadGateway ( MisfitHttpException ) : <EOL> pass <EOL> class MisfitUnauthorized ( MisfitHttpException ) : <EOL> pass <EOL> class MisfitForbidden ( MisfitHttpException ) : <EOL> pass <EOL> class MisfitRateLimitError ( MisfitHttpException ) : <EOL> pass <EOL> class MisfitUnknownError ( MisfitHttpException ) : <EOL> pass </s>
