package gov.samhsa.c2s.c2suiapi.service;

import gov.samhsa.c2s.c2suiapi.infrastructure.TryPolicyClient;
import org.springframework.stereotype.Service;

import java.util.Locale;

@Service
public class TryPolicyServiceImpl implements TryPolicyService {
    private final TryPolicyClient tryPolicyClient;

    public TryPolicyServiceImpl(TryPolicyClient tryPolicyClient) {
        this.tryPolicyClient = tryPolicyClient;
    }

    @Override
    public Object getSegmentDocXHTML(String documentId, String consentId, String patientId, String purposeOfUse, Locale locale) {
          return tryPolicyClient.tryPolicyByConsentIdXHTML(documentId, consentId, patientId, purposeOfUse, locale);
    }
}

@@ -98,16 +98,85 @@
 Client;%0A
+import gov.samhsa.c2s.c2suiapi.service.exception.TryPolicyException;%0A
 import o
@@ -206,32 +206,32 @@
 eotype.Service;%0A
-
 %0Aimport java.uti
@@ -644,16 +644,78 @@
     
-  return
+Object tryPolicyResponse;%0A        try%7B%0A            tryPolicyResponse =
  try
@@ -810,16 +810,256 @@
 ocale);%0A
+        %7Dcatch (Exception e)%7B%0A            //Todo: Refactor this block to watch for specific error status codes and throw custom exception%0A            throw new TryPolicyException(e.getMessage());%0A        %7D%0A        return tryPolicyResponse;%0A
     %7D%0A%7D%0A

Split into declaration and assignment