Skip to content

Commit

Permalink
No longer logging a TypeError if xcube server's
Browse files Browse the repository at this point in the history
  `GET viewer/ext/contributions` is called without any
  viewer extensions configured.
  • Loading branch information
forman committed Jan 29, 2025
1 parent c0ada5a commit a9fc399
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 7 deletions.
6 changes: 6 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
## Changes in 1.8.2 (in development)

* No longer logging a `TypeError` if xcube server's
`GET viewer/ext/contributions` is called without any
viewer extensions configured. (#1116)

## Changes in 1.8.1

### Fixes
Expand Down
2 changes: 1 addition & 1 deletion xcube/version.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
# Permissions are hereby granted under the terms of the MIT License:
# https://opensource.org/licenses/MIT.

version = "1.8.1"
version = "1.8.2.dev0"
30 changes: 24 additions & 6 deletions xcube/webapi/viewer/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,17 +163,31 @@ def new_key(self, length: int = 8) -> str:

class ViewerExtHandler(ApiHandler[ViewerContext]):
def do_get_contributions(self):
self._write_response(get_contributions(self.ctx.ext_ctx))
if self.ctx.ext_ctx is None:
self._write_no_ext_status()
else:
self._write_response(get_contributions(self.ctx.ext_ctx))

def do_get_layout(self, contrib_point: str, contrib_index: str):
self._write_response(
get_layout(
self.ctx.ext_ctx, contrib_point, int(contrib_index), self.request.json
if self.ctx.ext_ctx is None:
self._write_no_ext_status()
else:
self._write_response(
get_layout(
self.ctx.ext_ctx,
contrib_point,
int(contrib_index),
self.request.json,
)
)
)

def do_get_callback_results(self):
self._write_response(get_callback_results(self.ctx.ext_ctx, self.request.json))
if self.ctx.ext_ctx is None:
self._write_no_ext_status()
else:
self._write_response(
get_callback_results(self.ctx.ext_ctx, self.request.json)
)

def _write_response(self, response: ExtResponse):
self.response.set_header("Content-Type", "text/json")
Expand All @@ -187,6 +201,10 @@ def _write_response(self, response: ExtResponse):
{"error": {"status": response.status, "message": response.reason}}
)

def _write_no_ext_status(self):
self.response.set_status(404, "No extensions configured")
self.response.finish()


@api.route("/viewer/ext/contributions")
class ViewerExtContributionsHandler(ViewerExtHandler):
Expand Down

0 comments on commit a9fc399

Please sign in to comment.