""" Custom extension for GMS server """ import termcolor from django.http import HttpResponse from django.conf import settings class SystemException(Exception): """ Class to manage system exceptions. When return that exception if django.setting.DEBUG is true the exception arise as normal (Printing output in log and web). But if django.setting.DEBUG is false only a HTTP code 500 is send to web. Parameters ---------- args: iter Lenght=1, The message. Attributes ---------- message: str Message explaining why this exception occurs. """ def __init__(self, *args): super().__init__(*args) self.message = args[0] def get(self, _): """ Method executed when the exception is returnes as an httpResponse Parameters ---------- _ Returns ------- """ if settings.DEBUG: raise Exception(self.message) else: return HttpResponse(status=500) def __str__(self): return termcolor.colored(super().__str__(), 'red')