diff --git a/noctua/utils/check.py b/noctua/utils/check.py index 7233d1db8f81417f7f41012f85a9584fba6fd368..a697beae44ad6a3566dce0caeda432371793ab2b 100644 --- a/noctua/utils/check.py +++ b/noctua/utils/check.py @@ -55,7 +55,6 @@ def content_errors(content): return content_errors_inner - def request_errors(func): ''' Decorator for handling exceptions on a class method. @@ -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" - log.error(msg) - this.error.append(res.text.replace("\r\n", " ")) + # 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(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