Code Monkey home page Code Monkey logo

Comments (4)

downdawn avatar downdawn commented on May 20, 2024

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

from fastapi_best_architecture.

wu-clan avatar wu-clan commented on May 20, 2024

Of course

I ignored this situation in the test.

from fastapi_best_architecture.

wu-clan avatar wu-clan commented on May 20, 2024

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

from fastapi_best_architecture.

downdawn avatar downdawn commented on May 20, 2024

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

from fastapi_best_architecture.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.