Skip to content

Commit

Permalink
GIT-2045: rename api version mismatch exception
Browse files Browse the repository at this point in the history
  • Loading branch information
harshanarayana committed Mar 6, 2021
1 parent 9b1f6e9 commit db1f6fa
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 10 deletions.
4 changes: 2 additions & 2 deletions sanic/blueprint_group.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from typing import List

import sanic
from sanic.exceptions import RouteConfigurationException
from sanic.exceptions import APIVersionMismatchException


class BlueprintGroup(MutableSequence):
Expand Down Expand Up @@ -152,7 +152,7 @@ def insert(self, index: int, item: "sanic.blueprints.Blueprint") -> None:
:return: None
"""
if self._version and item.version and self._version != item.version:
raise RouteConfigurationException(
raise APIVersionMismatchException(
f"API Version Mismatch. Blueprint {item.name} has version {item.version} "
f"while Blueprint Group has {self._version}"
)
Expand Down
10 changes: 7 additions & 3 deletions sanic/blueprints.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

from sanic.base import BaseSanic
from sanic.blueprint_group import BlueprintGroup
from sanic.exceptions import RouteConfigurationException
from sanic.exceptions import APIVersionMismatchException
from sanic.handlers import ListenerType, MiddlewareType, RouteHandler
from sanic.models.futures import FutureRoute, FutureStatic

Expand Down Expand Up @@ -109,10 +109,14 @@ def chain(nested) -> Iterable[Blueprint]:
else:
yield i

bps = BlueprintGroup(url_prefix=url_prefix, version=version, strict_slashes=strict_slashes)
bps = BlueprintGroup(
url_prefix=url_prefix,
version=version,
strict_slashes=strict_slashes,
)
for bp in chain(blueprints):
if bp.version and version and bp.version != version:
raise RouteConfigurationException(
raise APIVersionMismatchException(
f"API Version Mismatch. Blueprint {bp.name} has version {bp.version} "
f"while Blueprint Group has {version}"
)
Expand Down
6 changes: 4 additions & 2 deletions sanic/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,12 @@ def __init__(self, message, status_code=None, quiet=None):
self.quiet = True


class RouteConfigurationException(SanicException):
class APIVersionMismatchException(SanicException):
"""
Exception generated for route setup configuration workflow
Exception generated for route setup configuration workflow when blueprint and blueprint-groups
are being configured to use two different API Versions
"""

pass


Expand Down
4 changes: 1 addition & 3 deletions sanic/websocket.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,9 +176,7 @@ async def accept(self) -> None:
await self._send(
{
"type": "websocket.accept",
"subprotocol": ",".join(
list(self.subprotocols)
),
"subprotocol": ",".join(list(self.subprotocols)),
}
)

Expand Down

0 comments on commit db1f6fa

Please sign in to comment.