On Wed, Jul 15, 2009 at 11:30:40PM +0200, Roan Kattouw wrote:
As of r52190 [1], API maxlag errors (the kind of error you get when
you set &maxlag=2 and the maximum slave lag is higher than two
seconds) return a HTTP 503 status code rather than a 200, for
consistency with index.php (which does the same thing).
I agree with the others, this change should be reverted, as it is an
arbitrary breaking change that makes things more difficult for API
clients for consistency with something that is not really related.
index.php returns an HTTP 503 error because it speaks HTTP, and that's
how you return errors in HTTP. But the API doesn't speak HTTP, it just
uses HTTP as a ''transport layer'' and reports its errors using its own
protocol. This change raises maxlag from an API-level error (where it
belongs) to a transport-level error; it's the same as if we would have
index.php return an ICMP error for maxlag.
Be aware that some client libraries may treat the 503
return code
differently, which is why this could be a breaking change.
That's an understatement. Any logically-coded client library that
bothers to check for errors will probably work something like this:
$response = send_http_request($uri, $postdata);
if ($response->is_http_error()) {
// Handle error
return null;
}
$result = parse_api_response($response->get_content());
if ($result == null) {
// Handle "unparsable response" error
return null;
}
// Any special API error logging/handling here
return $result;
As a result of r52190, that must become rather more complicated:
$response = send_http_request($uri, $postdata);
if ($response->http_status_code() == 503) {
// Maybe a maxlag error? Or maybe a real HTTP error, in which case
// parse_api_response() should fail?
$result = parse_api_response($response->get_content());
if ($result != null) {
// Any maxlag-specific special error logging/handling here
return $result;
}
}
if ($response->is_http_error()) {
// Handle error
return null;
}
$result = parse_api_response($response->get_content());
if ($result == null) {
// Handle "unparsable response" error
return null;
}
// Any special API error logging/handling here
return $result;