Fix exception handler parameter call#253
Conversation
# Conflicts: # backend/app/common/exception/exception_handler.py
|
PLR. |
| message += f'{data.get(field, field) if field != "__root__" else ""} {msg}' + '.' | ||
| elif isinstance(raw_error.exc, json.JSONDecodeError): | ||
| message += 'json解析失败' | ||
| raw_error = exc.raw_errors[0] |
There was a problem hiding this comment.
The loop is no longer used because we end up returning only one error message, the loop outputs the last error message, and using slices outputs the first error message.
This is done to be compatible with the logic in v2, making it less confusing during the migration.
There was a problem hiding this comment.
raw_error = exc.raw_errors[0] if exc.raw_errors else None
Would this way be better?
There was a problem hiding this comment.
In fact, if raw_errors is empty, raw_errors[0] will raise an error. The same error will occur for for raw_error in exc.raw_errors.
If add if exc.raw_errors..., an exception will be thrown only when raw_exc = raw_error.exc is encountered. Clearly, this is not compatible.
| message += f'{data.get(field, field) if field != "__root__" else ""} {msg}' + '.' | ||
| elif isinstance(raw_error.exc, json.JSONDecodeError): | ||
| message += 'json解析失败' | ||
| raw_error = exc.raw_errors[0] |
There was a problem hiding this comment.
raw_error = exc.raw_errors[0] if exc.raw_errors else None
Would this way be better?
* Fix exception handler parameter call * update the validation exception handler * Update the content returned by the validation exception * update import of JSONDecodeError * fix validation exception handler typing * Update the content returned by the validation exception handler
WIP.