Javascript Promises

<!doctype html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <title>Javascript Promis test</title>
  <script src="https://code.jquery.com/jquery-1.12.4.js"></script>
  <script>
  


	function fillData(){
		return new Promise(function(resolve,reject){

		
			$.ajax(
			   {
			      type:'GET',
			      url:'https://reqres.in/api/users/2',
			      success: function(data){
				 resolve(data);
				
			      },
			      error: function(err){
				reject(err);
			      }
			   }
			);
		});
	}

	function fillData2(){
		return new Promise(function(resolve,reject){

		
			$.ajax(
			   {
			      type:'GET',
			      url:'https://wrongapi.com/api/ussssers/2',
			      success: function(data){
				 resolve('success');
				
			      },
			      error: function(err){
				reject('fail');
			      }
			   }
			);
		});
	}
      
       function getUserProfile(){
	
	var userData=fillData().then(function(response){ 
	console.log(response); //response of first ajax function
	//some work here
	return fillData2(); //call tosecond ajax function
	}).
	then(function(response){ 
	console.log(response); //response of second ajax function
	}).
	catch(function(err){
	console.log(err); //if in any request it fails
	});
	
	
	}


</script>
</head>
<body>
 
<p>Promises Test</p>
<input type="button" onclick="getUserProfile()">
</body>
</html>

OutPUT

Object {data: Object}
GET https://reqssres.in/api/ussssers/2 net::ERR_NAME_NOT_RESOLVED //error thrown by network
fail