Allow to pass error-handlers to a `Validator`-instance
See original GitHub issuethis is a follow-up to #89 and #90.
i propose to introduce error-handlers in order to allow to deal with errors more flexible.
to achieve that:
Validator.__init__
takes an optionalerror_handler
-objectValidator._error
is extended, so it stores the following data about an error:trail
- a list that represents the path to thefield
in the document (eg:['a_dict', 'a_list']
); a common prefix can be specified upon callingValidator.validate
field
,value
- as of nowconstraint
- the constraint that failedmessage
- a simple error message, like currently implemented
Validator.errors
calls theformat
(?)-method oferror_handler
that may return errors in a desired format and / or do whatever its purpose is
there will be one default-handler and two as reference-implementations:
BasicErrorHandler
- returns errors as now
- but concentates
trail
andfield
HumanReadableErrorHandler
- is targeted to end-users
- concentates
trail
andfield
- suggests valid keys, in case of an unallowed value
- the index of list-items is increased by one
- list-items are prefixed with
item #
YamlErrorHandler
- structures errors in a dictionary
- joins it into a yaml-file
Issue Analytics
- State:
- Created 8 years ago
- Comments:6 (5 by maintainers)
Top Results From Across the Web
Errors & Error Handling - python-cerberus.org
The error handler to be used can be passed as keyword-argument error_handler to the initialization of a validator or by setting it's property...
Read more >Global error handler for any exception - python - Stack Overflow
I can't use the got_request_exception signal, as it is not allowed to modify the response (http://flask.pocoo.org/docs/0.10/signals/). In contrast all signal ...
Read more >Error Handlers | MuleSoft Documentation
When a flow is processing a Mule message that raises an error, the normal execution of the flow stops, and the process transfers...
Read more >Error Handler - Apache Camel
The error handler is scoped as either: CamelContext - Globally in XML or globally only within the same RouteBuilder in Java DSL. Route...
Read more >Handling Application Errors — Flask Documentation (2.2.x)
An error handler is a function that returns a response when a type of error is raised, ... a “405 Method Not Allowed”...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Is
HumanReadableErrorHandler
implemented? Couldn’t find the documentation.closing this as the core interface is now available.