Loading noctua/utils/check.py +25 −10 Original line number Diff line number Diff line Loading @@ -55,7 +55,6 @@ def content_errors(content): return content_errors_inner def request_errors(func): ''' Decorator for handling exceptions on a class method. Loading @@ -78,17 +77,33 @@ def request_errors(func): res = e.response if res.status_code == 400: # '0x80001005\r\nThe Error Message\r\n' msg = f"{name}: Device error" # API returns body like: '0x8000100a\r\nParameter(s) missing.\r\n' try: # Attempt to parse the API-specific error body_lines = res.text.strip().split('\r\n') error_code = body_lines[0] error_message = body_lines[1] if len(body_lines) > 1 else "No error message provided." msg = f"{name}: Bad Request - API Error {error_code}: {error_message}" log.error(msg) this.error.append(res.text.replace("\r\n", " ")) this.error.append(msg) except (IndexError, AttributeError): # Fallback for unexpected 400 error format msg = f"{name}: Bad Request with unparsable body." log.error(msg) log.error(f"Raw response: {res.text}") this.error.append(msg) elif res.status_code == 500: log.error(res.reason) # Device error log.error(res.text) this.error.append(res.reason) msg = f"{name}: Internal Server Error on device." log.error(msg) log.error(f"Reason: {res.reason}") log.error(f"Response: {res.text}") this.error.append(msg) this.error.append(res.text) else: # 404 log.error(e) # Not found else: # 404 Not Found, etc. msg = f"{name}: HTTP Error - {e}" log.error(msg) this.error.append(str(e)) return Loading Loading
noctua/utils/check.py +25 −10 Original line number Diff line number Diff line Loading @@ -55,7 +55,6 @@ def content_errors(content): return content_errors_inner def request_errors(func): ''' Decorator for handling exceptions on a class method. Loading @@ -78,17 +77,33 @@ def request_errors(func): res = e.response if res.status_code == 400: # '0x80001005\r\nThe Error Message\r\n' msg = f"{name}: Device error" # API returns body like: '0x8000100a\r\nParameter(s) missing.\r\n' try: # Attempt to parse the API-specific error body_lines = res.text.strip().split('\r\n') error_code = body_lines[0] error_message = body_lines[1] if len(body_lines) > 1 else "No error message provided." msg = f"{name}: Bad Request - API Error {error_code}: {error_message}" log.error(msg) this.error.append(res.text.replace("\r\n", " ")) this.error.append(msg) except (IndexError, AttributeError): # Fallback for unexpected 400 error format msg = f"{name}: Bad Request with unparsable body." log.error(msg) log.error(f"Raw response: {res.text}") this.error.append(msg) elif res.status_code == 500: log.error(res.reason) # Device error log.error(res.text) this.error.append(res.reason) msg = f"{name}: Internal Server Error on device." log.error(msg) log.error(f"Reason: {res.reason}") log.error(f"Response: {res.text}") this.error.append(msg) this.error.append(res.text) else: # 404 log.error(e) # Not found else: # 404 Not Found, etc. msg = f"{name}: HTTP Error - {e}" log.error(msg) this.error.append(str(e)) return Loading