Skip to content
Snippets Groups Projects
Commit d66a1b4c authored by Georges Racinet's avatar Georges Racinet
Browse files

errors: helper for NOT_FOUND

As said in the docstring, we don't gain that much, especially
with the caller probably needing a multi-line statement.

Still it's a bit less painful to use, and good for uniformity.
parent c743e54c
No related branches found
No related tags found
1 merge request!13Helper for proper NOT_FOUND gRPC responses
......@@ -36,3 +36,22 @@
logger.error(msg)
context.set_details(msg)
return response_cls()
def not_found(context, response_cls, message, log_level=logging.WARNING):
"""Return grpc proper NOT_FOUND code with message.
This helper method saves at most 3 lines of code, and that makes a
difference for repetitive error treatment. It's also good for
uniformity.
The default value for `log_level` is based on the assumption that
the client should have the means to perform calls that don't end up
in gRPC errors, be it by before hand knowledge or by using calls that
have a specified return for missing content. Still, ``log_level`` is
provided for cases where the server would know that warnings are too much.
"""
context.set_code(StatusCode.NOT_FOUND)
logger.log(log_level, message)
context.set_details(message)
return response_cls()
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment