request / promise-core

Core Promise support implementation for the simplified HTTP request client 'request'.
ISC License
20 stars 43 forks source link

Allow transform non-2xx request to 2xx request in simple mode. #2

Open Gerhut opened 8 years ago

Gerhut commented 8 years ago

Used in transform 304 response to 200 response with local cache.

analog-nico commented 8 years ago

That is a very good idea!

This would mean the transform function would just change the statusCode and the response would be "reresolved" accordingly.

function (body, response, resolveWithFullResponse) {
    // Get data from the cache etc.
    response.statusCode = 200
    return response
}

However, this solution doesn't go with resolveWithFullResponse = false yet...

Gerhut commented 8 years ago

If resolveWithFullResponse = false set, it usually means the status code (also headers etc) are not important to the coder. So I think just retain the status code when resolveWithFullResponse = false is OK

analog-nico commented 8 years ago

Just to make sure I really understand you correctly:

  1. You do a request with option simple = true
  2. The server sends a 304 response
  3. You apply the transform that shall be able to change the statusCode to 200
  4. request-promise does not return the response to .catch(...) anymore
  5. Instead, request-promise returns the response to .then(...)

Correct? Or are you working with simple = false to begin with and are not worried about getting the response returned to .catch(...) anyway?

Gerhut commented 8 years ago

Yep this is my opinion.

I tried to working with simple = false, but I also need others rejections like 404.

Transform non-304 into rejection under simple = false makes my code even more complicated...

Sincerely George Chung

2016-09-28 1:35 GMT+08:00 Nicolai Kamenzky notifications@github.com:

Just to make sure I really understand you correctly:

  1. You do a request with option simple = true
  2. The server sends a 304 response
  3. You apply the transform that shall be able to change the statusCode to 200
  4. request-promise does not return the response to .catch(...) anymore
  5. Instead, request-promise returns the response to .then(...)

Correct? Or are you working with simple = false to begin with and are not worried about getting the response returned to .catch(...) anyway?

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/request/promise-core/issues/2#issuecomment-249938821, or mute the thread https://github.com/notifications/unsubscribe-auth/ACYml2U8EOgGVU_f3YeSTBP1m6cHAd0lks5quVP1gaJpZM4KCnAF .