Skip to content

Commit

Permalink
Merge pull request #490 from Ouranosinc/log-failed-service
Browse files Browse the repository at this point in the history
  • Loading branch information
fmigneault authored Dec 7, 2021
2 parents 87fe4d7 + 4cdf19f commit 14e31f2
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions magpie/services.py
Original file line number Diff line number Diff line change
Expand Up @@ -973,14 +973,23 @@ def service_factory(service, request):
"""
ax.verify_param(service, param_compare=models.Service, is_type=True,
http_error=HTTPBadRequest, content={"service": repr(service)},
msg_on_fail="Cannot process invalid service object")
msg_on_fail="Cannot process invalid service object.")
service_type = ax.evaluate_call(lambda: service.type, http_error=HTTPInternalServerError,
msg_on_fail="Cannot retrieve service type from object")
msg_on_fail="Cannot retrieve service type from object.")
ax.verify_param(service_type, is_in=True, param_compare=SERVICE_TYPE_DICT.keys(),
http_error=HTTPNotImplemented, content={"service_type": service_type},
msg_on_fail="Undefined service type mapping to service object")
return ax.evaluate_call(lambda: SERVICE_TYPE_DICT[service_type](service, request),
http_error=HTTPInternalServerError,
msg_on_fail="Undefined service type mapping to service object.")

def _make_service(_typ, _svc, _req):
try:
return SERVICE_TYPE_DICT[_typ](_svc, _req)
except Exception as exc:
LOGGER.debug("Failed service creation using (type [%s], service [%s], request [%s]). Exception: [%s] (%s).",
_typ, _svc, _req, type(exc).__name__, exc, exc_info=exc)
raise

return ax.evaluate_call(lambda: _make_service(service_type, service, request),
http_error=HTTPInternalServerError, content={"service_type": service_type},
msg_on_fail="Failed to find requested service type.")


Expand Down

0 comments on commit 14e31f2

Please sign in to comment.