Skip to content

Commit

Permalink
Python-lib: Make M1 Client pass the ProblemDetails object from an err…
Browse files Browse the repository at this point in the history
…or response
  • Loading branch information
davidjwbbc committed Jul 12, 2024
1 parent c7ac16f commit 341dffe
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions python/lib/rt_m1_client/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,14 @@
import json
import logging
from typing import Optional, Union, Tuple, Dict, Any, TypedDict, List
#import traceback

import httpx

from .exceptions import (M1ClientError, M1ServerError)
from .types import (ApplicationId, ContentHostingConfiguration, ContentProtocols,
ConsumptionReportingConfiguration, PolicyTemplate, MetricsReportingConfiguration,
ProvisioningSessionType, ProvisioningSession, ResourceId)
ProvisioningSessionType, ProvisioningSession, ResourceId, ProblemDetail)

class TagAndDateResponse(TypedDict, total=False):
'''Response containing ETag and Last-Modified headers
Expand Down Expand Up @@ -903,12 +904,21 @@ def __default_response(self, result: Dict[str,Any]) -> None:
:raise M1ClientError: if there was a problem with the request.
:raise M1ServerError: if there was a server side issue preventing the creation of the provisioning session.
'''
problem_detail = None
if 'Content-Type' in result['headers']:
if result['headers']['Content-Type'] in ['application/problem+json', 'application/json']:
try:
problem_detail = ProblemDetail.fromJSON(result['body'])
except Exception:
#traceback.print_exc()
pass

if result['status_code'] >= 400 and result['status_code'] < 500:
raise M1ClientError(reason='M1 operation failed: '+str(result['body']),
status_code=result['status_code'])
status_code=result['status_code'], problem_detail=problem_detail)
if result['status_code'] >= 500 and result['status_code'] < 600:
raise M1ServerError(reason='M1 operation failed: '+str(result['body']),
status_code=result['status_code'])
status_code=result['status_code'], problem_detail=problem_detail)

@staticmethod
def __tag_and_date(result: Dict[str,Any]) -> TagAndDateResponse:
Expand Down

0 comments on commit 341dffe

Please sign in to comment.