All files / Api/Playback/Utils intercetpPlaybackServiceResponse.js

100% Statements 5/5
100% Branches 2/2
100% Functions 0/0
100% Lines 4/4

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 421x           1x   1x   17x                                                              
import {
    never,
    of,
} from 'rxjs';
 
import isEmpty from '../../../Shared/Utils/isEmpty';
import ErrorType from '../../../Errors/Constants/Error.type';
 
const intercetpPlaybackServiceResponse = handleError => serviceResponse => {
    if (isEmpty(serviceResponse) || typeof serviceResponse !== 'object') {
        handleError({
            type: ErrorType.API_SERVICE_PLAYBACK_MISSING_DATA,
            source: new Error(ErrorType.API_SERVICE_PLAYBACK_MISSING_DATA),
        });
        return never();
    }
 
    const response = Object
        .keys(serviceResponse)
        .reduce((output, currentService) => {
            const service = serviceResponse[currentService];
 
            if (isEmpty(service)) {
                const type = `API_SERVICE_PLAYBACK_${currentService.toUpperCase()}_UNAVAILABLE`;
                const source = new Error(type);
                handleError({
                    type,
                    source,
                });
                output[currentService] = null;
            } else {
                output[currentService] = service;
            }
 
            return output;
        }, {});
 
    return of(response);
};
 
export default intercetpPlaybackServiceResponse;