nst / STHTTPRequest

Obj-C / Cocoa HTTP requests for humans
BSD 3-Clause "New" or "Revised" License
826 stars 75 forks source link

Question: Get body data if Error #52

Closed NikKovIos closed 6 years ago

NikKovIos commented 6 years ago

When it is an error, we use request.errorBlock = ^(NSError *error) {} But what if i need to fetch a response body, when it is an error? What should i do?

nst commented 6 years ago

You can use request.responseString in errorBlock.

NikKovIos commented 6 years ago

Thx! Note: Capturing 'request' strongly in this block is likely to lead to a retain cycle so use
__weak typeof(request) weakRequest = request; weakRequest.responseString in block.

Thumbs up if helped.