(exc: Exception, config: Type['BaseConfig'], loc: 'Loc')
| 117 | |
| 118 | |
| 119 | def error_dict(exc: Exception, config: Type['BaseConfig'], loc: 'Loc') -> 'ErrorDict': |
| 120 | type_ = get_exc_type(exc.__class__) |
| 121 | msg_template = config.error_msg_templates.get(type_) or getattr(exc, 'msg_template', None) |
| 122 | ctx = exc.__dict__ |
| 123 | if msg_template: |
| 124 | msg = msg_template.format(**ctx) |
| 125 | else: |
| 126 | msg = str(exc) |
| 127 | |
| 128 | d: 'ErrorDict' = {'loc': loc, 'msg': msg, 'type': type_} |
| 129 | |
| 130 | if ctx: |
| 131 | d['ctx'] = ctx |
| 132 | |
| 133 | return d |
| 134 | |
| 135 | |
| 136 | _EXC_TYPE_CACHE: Dict[Type[Exception], str] = {} |
no test coverage detected