0

I have a Siesta resource to which I use the closure version of AddObserver. Right now, the endpoint that that resource uses always returns a 404. Most of the time, the observing closure only gets called once with the error. However, I have a log file where I see the exact same error (same timestamp and everything) being called twice. The error looks like this:

RequestError(userMessage: "Not found", httpStatusCode: Optional(404), entity: Optional(Siesta.Entity<Any>(content: "<h2>404 - Page Not Found</h2><p>The page could not be found.</p>", charset: Optional("utf-8"), headersNormalized: ["access-control-allow-headers": "Content-Type, Authorization", "set-cookie": "connect.sid=s%3APGOwgU4q3fhlxhag0E9Sc1zN_R9jTjH0.IAp%2BfAIfqxqP%2Bt5zZ1f0t1terpWgoRHpQhF%2BfB0gxyw; Path=/; HttpOnly", "etag": "W/\"40-ca3ea152\"", "via": "1.1 vegur", "content-length": "64", "content-type": "text/html; charset=utf-8", "date": "Sun, 17 Sep 2017 01:05:43 GMT", "access-control-allow-methods": "DELETE,GET,PATCH,POST,PUT", "connection": "keep-alive", "x-powered-by": "Express", "vary": "Accept-Encoding", "server": "Cowboy", "access-control-allow-origin": "*"], timestamp: 527303143.37699503)), cause: nil, timestamp: 527303143.37563998)

Are there cases where I should receive this error twice? Is it not a guarantee that the observer is only called once in this situation? Is it a bug??? Is that bug in Siesta, the networking library, or my code?

Jordan Wood
  • 2,727
  • 3
  • 12
  • 17
  • It’s only `Request` that guarantees one call per callback; observers can be called any number of times when any part of the resource’s state changes. So this _might_ not be a bug, but it is suspicious. Two ideas: (1) What events is the observer receiving? Is it `error` both times? Or maybe it’s `requested` again while it already has an error? (2) Unlike object observers, Siesta doesn’t de-dup closure observers. Maybe you’re adding it twice? – Paul Cantrell Sep 18 '17 at 14:37
  • I was not logging the event, just the `latestError`. I've added a message to my log should this happen again. I did look pretty closely to see if I'm calling `addObserver` with that closure more than once, and I'm pretty sure that didn't happen. I don't know if I'm going to be able to reproduce this, we'll see. – Jordan Wood Sep 18 '17 at 15:52

0 Answers0