Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

raw_exc.errors() exception #150

Closed
downdawn opened this issue Jun 19, 2023 · 4 comments · Fixed by #151
Closed

raw_exc.errors() exception #150

downdawn opened this issue Jun 19, 2023 · 4 comments · Fixed by #151

Comments

@downdawn
Copy link
Collaborator

downdawn commented Jun 19, 2023

When creating a department, if the mailbox format and status are incorrect, an exception will be thrown:

{
  "code": 500,
  "msg": "'permitted'",
  "data": null
}
@downdawn
Copy link
Collaborator Author

downdawn commented Jun 19, 2023

Traverse processing

  # 处理特殊类型异常模板信息 -> backend/app/schemas/base.py: SCHEMA_ERROR_MSG_TEMPLATES
  for sub_raw_error in raw_exc.raw_errors:
      sub_raw_exc = sub_raw_error.exc
      if isinstance(sub_raw_exc, (EnumMemberError, WrongConstantError)):
          if getattr(sub_raw_exc, 'code') == 'enum':
              sub_raw_exc.__dict__['permitted'] = ', '.join(repr(v.value) for v in sub_raw_exc.enum_values)  # type: ignore  # noqa: E501
          else:
              sub_raw_exc.__dict__['permitted'] = ', '.join(repr(v) for v in sub_raw_exc.permitted)  # type: ignore  # noqa: E501
  # 处理异常信息
  for error in raw_exc.errors()[:1]:
      field = str(error.get('loc')[-1])
      msg = error.get('msg')
      message += (
          f'{data.get(field, field) if field != "__root__" else ""} {msg}' + '.'
      )

output:

{
  "code": 422,
  "msg": "请求参数非法: email 邮箱格式错误.",
  "data": null
}

If there is no problem, I will submit pr

@wu-clan
Copy link
Member

wu-clan commented Jun 19, 2023

Of course

I ignored this situation in the test.

@wu-clan
Copy link
Member

wu-clan commented Jun 19, 2023

It is recommended to keep errors_len, which is used to beautify the output.

@downdawn
Copy link
Collaborator Author

There should be only one error, and each error should be resolved

@downdawn downdawn linked a pull request Jun 19, 2023 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants