Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add options to response #188

Closed
wants to merge 1 commit into from
Closed

Add options to response #188

wants to merge 1 commit into from

Commits on Mar 25, 2016

  1. Add options to response

    Hi. I'm not sure if im doing it the correct way or if you want this in the repo, but this is the solution i found to he following problem:
    
    I have a promise code like this:
    ```
    requestsPromise = [];
    PackofURL.forEach((thisUrl) => {
    	var thisRequest = got(thisUrl.url);
    	requestsPromise.push(thisRequest);
    });
    
    return Promise.all(requestsPromise)
    	.then((allRequests) => {
    		allRequests.forEach((thisRequest, index) => {
    			if(CheckURLForSomething(thisRequest)) {
    				Requester.doSomething(thisRequest);
    			}
    		});
    	});
    ```
    If the request returns `200` i pass it into `CheckURLForSomething` and it will hash the url to store as a key of another part of the code.
    The problem is that i could not build the full URL (protocol + host + path + query) with the response.
    
    I could do something like this:
    ```
    PackofURL.forEach((thisUrl) => {
    	var thisRequest = got(thisUrl.url)
    		.then((response) => { return Promise.resolve({ fullUrl: thisUrl.url, response: response }); });
    
    	requestsPromise.push(thisRequest);
    });
    
    return Promise.all(requestsPromise)
    	.then((allRequests) => {
    		allRequests.forEach((thisRequest, index) => {
    			if(CheckURLForSomething(thisRequest.fullUrl)) {
    				Requester.doSomething(thisRequest.response);
    			}
    		});
    	});
    ```
    
    But maybe more people have the same problem and with this change i can get just `thisRequest.request.href`.
    If you want this in the code, let me know if i should change anything.
    luanmuniz committed Mar 25, 2016
    Configuration menu
    Copy the full SHA
    ea56364 View commit details
    Browse the repository at this point in the history