package gov.samhsa.c2s.c2suiapi.service;

import feign.FeignException;
import gov.samhsa.c2s.c2suiapi.infrastructure.PhrClient;
import gov.samhsa.c2s.c2suiapi.service.exception.NoDocumentsFoundException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class PhrServiceImpl implements PhrService{

    private final PhrClient phrClient;


    @Autowired
    public PhrServiceImpl(PhrClient phrClient) {
        this.phrClient = phrClient;
    }

    @Override
    public List<Object> getAllDocumentTypeCodesList(){
        return phrClient.getAllDocumentTypeCodesList();
    }

    @Override
    public List<Object> getPatientDocumentInfoList(String patientMrn){
        try{
            return phrClient.getPatientDocumentInfoList(patientMrn);
        }catch (FeignException fe){
            if(fe.status() == 404){
                throw new NoDocumentsFoundException(fe.getMessage());
            }
        }
        return null;
    }

}

@@ -31,24 +31,86 @@
 i.service;%0A%0A
+import com.netflix.hystrix.exception.HystrixRuntimeException;%0A
 import feign
@@ -122,24 +122,24 @@
 nException;%0A
-
 import gov.s
@@ -255,24 +255,81 @@
 dException;%0A
+import org.slf4j.Logger;%0Aimport org.slf4j.LoggerFactory;%0A
 import org.s
@@ -552,16 +552,93 @@
 lient;%0A%0A
+    private final Logger logger = LoggerFactory.getLogger(this.getClass());%0A%0A
 %0A    @Au
@@ -1054,47 +1054,148 @@
 atch
- (FeignException fe)%7B%0A            if(fe
+(HystrixRuntimeException err) %7B%0A            Throwable t = err.getCause();%0A            if(t instanceof FeignException && ((FeignException) t)
 .sta
@@ -1261,18 +1261,17 @@
 ception(
-fe
+t
 .getMess

Throw custom error when status code is 404