DataBrewery / cubes

[NOT MAINTAINED] Light-weight Python OLAP framework for multi-dimensional data analysis
http://cubes.databrewery.org
Other
1.49k stars 314 forks source link

Server Error is returned when a bad hierarchy is requested #384

Open duckpunch opened 8 years ago

duckpunch commented 8 years ago

Cubes raises a ModelError when a nonexistent hierarchy is requested via HTTP which results in a 500 response code. A better response code would be Bad Request (400).

This is problematic because HTTP clients can trigger 500s which in turn, trigger error emails for servers that are configured to send emails on 500s.

The source of the error is in the errorhandler for InternalError, which wraps ModelError.

I produced this behavior by accessing the following URL.

/cube/<some cube>/aggregate?drilldown=<existing dimension>@<nonexistent hierarchy>

The response was the following.

{
    "message": "Internal server error",
    "error": "internal_server_error",
    "hint": "Server administrators can learn more about the error from the error logs (even more if they have 'debug' level)"
}

The stack trace in logs looked like this.

Traceback (most recent call last):

  ...<unrelated stack trace>...

  File "/path/to/venv/lib/python3.4/site-packages/cubes/server/decorators.py", line 118, in wrapper
    return f(*args, **kwargs)
  File "/path/to/venv/lib/python3.4/site-packages/cubes/server/decorators.py", line 167, in wrapper
    retval = f(*args, **kwargs)
  File "/path/to/venv/lib/python3.4/site-packages/cubes/server/blueprint.py", line 352, in aggregate
    order=g.order)
  File "/path/to/venv/lib/python3.4/site-packages/cubes/browser.py", line 143, in aggregate
    drilldon = Drilldown(drilldown, cell)
  File "/path/to/venv/lib/python3.4/site-packages/cubes/browser.py", line 878, in __init__
    self.drilldown = levels_from_drilldown(cell, drilldown)
  File "/path/to/venv/lib/python3.4/site-packages/cubes/browser.py", line 1086, in levels_from_drilldown
    hier = dim.hierarchy(hier)
  File "/path/to/venv/lib/python3.4/site-packages/cubes/model.py", line 1242, in hierarchy
    (obj, self.name))
cubes.errors.ModelError: No hierarchy <missing hierarchy> in dimension <dimension>