lukeredpath / LRResty

Yet another Objective-C REST client library, inspired by Ruby's restclient gem.
http://projects.lukeredpath.co.uk/resty/
461 stars 56 forks source link

No timeout callbacks received from nightly #13

Closed mflint closed 13 years ago

mflint commented 13 years ago

Hello,

I'm using the very latest nightly, and struggling to get any timeout callbacks:

[[[LRResty client] get:@"http://127.0.0.1:8888/api" withBlock:^(LRRestyResponse *r) {
        NSLog(@"response");
    }] timeoutAfter:5 handleWithBlock:^(LRRestyRequest *r){
        NSLog(@"timeout");
    }];

If the service at "127.0.0.1:8888/api" is up, I see the response block executed as expected. But if I stop the service, then neither the response nor the timeout blocks are executed.

I've also tried setting a global timeout (with setGlobalTimeout:handleWithBlock:), but that block doesn't get called either.

Any ideas? I guess either my code is bad, or my expectations about how LRResty works are wrong.

Thanks folks!

Matthew

lukeredpath commented 13 years ago

Hi there, I can't seem to reproduce this problem. What version of iOS are you using?

mflint commented 13 years ago

This is using the iPhone simulator, v4.3., but building with the latest beta Xcode.

From your response, it sounds like my expectations are correct about how it should be working?

I'll have another go later today.

lukeredpath commented 13 years ago

Yes, your expectations are correct; please take a look at the TimeoutTests in the source for more examples.

mflint commented 13 years ago

I understand now...

Instead of causing a timeout, LRRestyRequest is gettingconnection:didFailWithError: callback form NSURLConnection, so my delegate should be responding to restyRequest:didFailWithError:.

I was using blocks, not the delegate - and LRRestyClientBlockDelegate doesn't handle that selector.

I'll close this. Thanks for listening! :-)

lukeredpath commented 13 years ago

No problem. Error handling for the block APIs definitely needs some work. It's on my TODO list.

mflint commented 13 years ago

As a workaround, I'll make my own version of LRRestyClientBlockDelegate which takes two blocks - one for the success case, t'other for failure - and then make a category to add get:withBlock:andErrorBlock to LRRestyClient.

krstns commented 12 years ago

mflint: would you mind sharing your workaround? I just hit the same problem as you did and would welcome a tested solution :)

And by the way, timeouts don't work either (I just put a breakpoint in my api and held the thread for longer than the time interval setting in lrresty and it would not call the timeout block).

mflint commented 12 years ago

@krstns I dropped the relevant stuff in a gist: https://gist.github.com/1384099

It adds a category to LRRestyClient, so I write code against LRRestyClient+FailureBlock.h instead.

But I don't remember saying anywhere that it's tested! :-p

krstns commented 12 years ago

Awesome :) Thanks a lot! I will give it a try now :)

kcorey commented 12 years ago

Hi All,

Having a real hard time wrapping my head around all this. The lack of timeout errors are driving me mad. I've tried seemingly a million things, and none of them make sense. (originally code similar to the stuff at the top of this thread, then mflint's solution, and by slowly adding breakpoints so I can see things happening).

Being an iOS newbie, I'm getting completely lost in all the blocks/delegates/proxies/protocols and whatever else is going on here. I feel like I'm just about the come to grips with it, and it all falls shattered to the ground.

Any chance someone could throw up a simple example of using LRResty with the ability to detect timeouts and other errors? I don't care if it's using the block syntax, the delegate syntax, or something else...just so long as the errors are reported back to my code so I can take appropriate action.

I'd sure appreciate it.

-Ken