Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Answer descriptive error when requesting too high API version #7424

Merged
merged 4 commits into from
Nov 8, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.unreleased.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ For upgrade instructions, please check the [migration guide](MIGRATIONS.released
- Added support for reading uint24 rgb layers in datasets with zarr2/zarr3/n5/neuroglancerPrecomputed format, as used for voxelytics predictions. [#7413](https://github.com/scalableminds/webknossos/pull/7413)

### Changed
- An appropriate error is returned when requesting an API version that is higher that the current version. [#7424](https://github.com/scalableminds/webknossos/pull/7424)

### Fixed
- Searching the segments in the sidebar will highlight newly focused segments properly now. [#7406](https://github.com/scalableminds/webknossos/pull/7406)
Expand Down
22 changes: 20 additions & 2 deletions app/RequestHandler.scala
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import com.scalableminds.util.mvc.ExtendedController
import com.typesafe.scalalogging.LazyLogging
import controllers.{Assets, WkorgProxyController, SitemapController}
import controllers.{Assets, SitemapController, WkorgProxyController}

import javax.inject.Inject
import play.api.OptionalDevContext
import play.api.http.{DefaultHttpRequestHandler, HttpConfiguration, HttpErrorHandler, HttpFilters}
Expand Down Expand Up @@ -27,9 +29,24 @@ class RequestHandler @Inject()(webCommands: WebCommands,
filters
)
with InjectedController
with ExtendedController
with LazyLogging {

override def routeRequest(request: RequestHeader): Option[Handler] =
private def CURRENT_API_VERSION = 5

override def routeRequest(request: RequestHeader): Option[Handler] = {
"^/api/v(\\d+).*$".r.findFirstMatchIn(request.uri) match {
case Some(m) =>
val version = m.group(1)
if (version.toInt > CURRENT_API_VERSION) {
return Some(Action {
JsonNotFound(
f"This WEBKNOSSOS instance does not yet support this API version. The requested API version $version is higher than the current API version $CURRENT_API_VERSION.")
})
}
case None =>
}

if (request.uri.matches("^(/api/|/data/|/tracings/|/swagger|/\\.well-known/).*$")) {
super.routeRequest(request)
} else if (request.uri.matches("^(/assets/).*$")) {
Expand All @@ -42,4 +59,5 @@ class RequestHandler @Inject()(webCommands: WebCommands,
} else if (request.uri == "/favicon.ico") {
Some(Action { NotFound })
} else Some(wkorgProxyController.proxyPageOrMainView)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,7 @@ trait MimeTypes {
trait JsonResults extends JsonResultAttribues {
val JsonOk = new JsonResult(OK)
val JsonBadRequest = new JsonResult(BAD_REQUEST)
val JsonNotFound = new JsonResult(NOT_FOUND)
}

trait JsonResultAttribues {
Expand Down