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

Fix error when decoding response from DNSaaS #3793

Merged
merged 2 commits into from
Feb 26, 2024
Merged
Changes from all 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
10 changes: 7 additions & 3 deletions src/ralph/dns/dnsaas.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
from functools import wraps
from typing import List, Optional, Tuple, Union
from urllib.parse import parse_qs, urlencode, urljoin, urlsplit

import requests
from dj.choices import Choices
from django.conf import settings
Expand Down Expand Up @@ -184,15 +183,20 @@ def update_dns_record(self, record: dict) -> Optional[dict]:
return response_data

@staticmethod
def _response2result(response: requests.Response) -> Union[dict, list]:
def _response2result(
response: requests.Response
) -> Union[dict, list, None]:
if response.status_code == 500:
logger.error('Internal Server Error from DNSAAS: %s',
response.content)
return {
'non_field_errors': ['Internal Server Error from DNSAAS']
}
elif response.status_code not in (202, 204):
return response.json()
try:
return response.json()
except ValueError:
pass

def create_dns_record(self, record: dict, service=None) -> Optional[dict]:
"""
Expand Down
Loading