-
-
Notifications
You must be signed in to change notification settings - Fork 953
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(media): let media handlers deserialize empty media (#1758)
* fear(media): let media handlers deserialize an empty media. * chore(pep8): fix style errors * chore(coverage): cover missing case * chore(typo): remove unused object * chore: update implementation based on feedback this is just a wip version to gather feedback * feat: update implementation of handler to raise consistent errors * test: complete request media tests * docs: updated docs and review comments * chore: MultipartParseError is now a subclass of MediaMalformedError * chore: improvement as per review * chore: allow overriding empty error * test: don't import msgpack globally * test: restore coverage to 100% * docs: improve documentation as per review comments * refactor: do not cache the default when empty value in get_media * chore: make coverage happy again * docs: improve docs after feedback Co-authored-by: Vytautas Liuolia <vytautas.liuolia@gmail.com> Co-authored-by: Kurt Griffiths <mail@kgriffs.com>
- Loading branch information
1 parent
26aa528
commit c7ab8da
Showing
17 changed files
with
501 additions
and
136 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
General refactoring of internal media handler: | ||
|
||
* Deserializing an empty body with a handler that does not support it will | ||
raise :class:`falcon.MediaNotFoundError`, and will be rendered as a | ||
``400 Bad Request`` response. This error may be suppressed by passing | ||
a default value to ``get_media`` to be used in case of empty body. | ||
See also :meth:`Request.get_media` for details. | ||
Previously ``None`` was returned in all cases without calling the handler. | ||
* Exceptions raised by the handlers are wrapped as | ||
:class:`falcon.MediaMalformedError`, and will be rendered as a | ||
``400 Bad Request`` response. | ||
* Subsequent calls to :meth:`Request.get_media` or :attr:`Request.media` will | ||
re-raise the same exception, if the first call ended in an error, unless the | ||
exception was a :class:`falcon.MediaNotFoundError` and a default value is | ||
passed to the ``default_when_empty`` attribute of the current invocation. | ||
Previously ``None`` was returned. | ||
|
||
External handlers should update their logic to align to the internal Falcon handlers. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.