MOBILE-3657 ws: Add throw on failed status helper function
This commit is contained in:
		
							parent
							
								
									8addd2074d
								
							
						
					
					
						commit
						9cdee6f68d
					
				@ -232,6 +232,22 @@ export class CoreWSProvider {
 | 
			
		||||
        return new CoreError(message);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * It will check if response has failed and throw the propper error.
 | 
			
		||||
     *
 | 
			
		||||
     * @param response WS response.
 | 
			
		||||
     * @param defaultMessage Message to be used in case warnings is empty.
 | 
			
		||||
     */
 | 
			
		||||
    throwOnFailedStatus(response: CoreStatusWithWarningsWSResponse, defaultMessage: string): void {
 | 
			
		||||
        if (!response.status) {
 | 
			
		||||
            if (response.warnings && response.warnings.length) {
 | 
			
		||||
                throw new CoreWSError(response.warnings[0]);
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            throw new CoreError(defaultMessage);
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Downloads a file from Moodle using Cordova File API.
 | 
			
		||||
     *
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user