All files / Api/Playback/Utils handlePlaybackServiceError.js

100% Statements 16/16
100% Branches 5/5
100% Functions 2/2
100% Lines 15/15

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        1x   1x 1x   11x   5x 5x 5x   5x   1x 1x     2x 2x     2x 2x     5x        
/**
 * @param  {string<ServiceType>} serviceType
 * @param  {ErrorsHandler.handleError} handleError
 */
import pathOr from 'ramda/src/pathOr';
 
import ErrorType from '../../../Errors/Constants/Error.type';
import ErrorPayload from '../../../Errors/Utils/ErrorPayload';
 
const handlePlaybackServiceError = handleError =>
    error => {
        let type;
        const API_ERROR_CODE_GENERIC = '10000';
        const apiErrorCode = pathOr(API_ERROR_CODE_GENERIC, ['response', 'data', 'odata.error', 'code'], error);
 
        switch (apiErrorCode.toString()) {
            case '10008':
                type = ErrorType.API_SERVICE_PLAYBACK_CONCURRENT_USER_LIMIT;
                break;
            case '10006':
            case '10013':
                type = ErrorType.API_SERVICE_PLAYBACK_RESTRICTED_LOCATION;
                break;
            case '10000':
            default:
                type = ErrorType.API_SERVICE_PLAYBACK;
                break;
        }
 
        handleError(new ErrorPayload(type, error));
    };
 
export default handlePlaybackServiceError;