Skip to content

Commit

Permalink
Support errors_as_json for InvalidKeysConfigurationError
Browse files Browse the repository at this point in the history
  • Loading branch information
cemathey committed May 28, 2024
1 parent 93ae6e6 commit 2f5d6da
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
2 changes: 1 addition & 1 deletion rcon/user_config/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ def __str__(self) -> str:
def __repr__(self) -> str:
return f"missing keys=({', '.join(self.missing_keys)}) | Extra keys = ({', '.join(self.extra_keys)}) | Mandatory keys=({', '.join(self.mandatory_keys)}) | Provided keys=({', '.join(self.provided_keys)})"

def asdict(self):
def asdict(self) -> dict[str, Any]:
return {
"type": InvalidKeysConfigurationError.__name__,
"missing_keys": sorted([k for k in self.missing_keys]),
Expand Down
6 changes: 6 additions & 0 deletions rconweb/api/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
PublicInfoType,
)
from rcon.user_config.rcon_server_settings import RconServerSettingsUserConfig
from rcon.user_config.utils import InvalidKeysConfigurationError
from rcon.utils import MapsHistory, get_server_number
from rcon.vote_map import VoteMap
from rconweb.settings import TAG_VERSION
Expand Down Expand Up @@ -254,6 +255,11 @@ def wrapper(request: HttpRequest):
error = e.json()
else:
error = str(e)
except InvalidKeysConfigurationError as e:
if errors_as_json:
error = e.asdict()
else:
error = str(e)
except CommandFailedError as e:
failure = True
error = e.args[0] if e.args else None
Expand Down

0 comments on commit 2f5d6da

Please sign in to comment.