- From: Mike Wilson <mikewse@hotmail.com>
- Date: Thu, 22 Feb 2007 16:51:30 +0100
- To: <public-webapi@w3.org>
- Message-ID: <BAY116-DAV15E95E2CFE00911FA73150A48F0@phx.gbl>
- Message-ID: <035601c75699$51cad1e0$0a01a8c0@mikedeskxp>
To be able to report network errors in a consistent way for asynchronous and synchronous requests, XHR could make use of deferred exceptions for the async case (assuming that sync requests will continue to throw NETWORK_ERR in future specs). This could be done by letting all properties that are results of the response throw a deferred NETWORK_ERR. Thus, a client script that sends an asynchronous XHR request and doesn't check on the response's status or content will not encounter the exception (which makes sense as it apparently isn't interested in the result). But a script checking response status or content will have the correct exception thrown at inspection time. See example below, where a network error would cause a deferred exception to be thrown at the test for "this.status == 200". function handler() { if (this.readyState == 4) { try { if (this.status == 200) { ... } } catch(netErr) { ... } } var client = new XMLHttpRequest(); client.onreadystatechange = handler; client.open("GET", "test.xml"); client.send(); This would offer a similar solution for async requests as for the synced, and throws exceptions at a point where they may be caught instead of going straight into the global error handler, which has been discussed as a problem earlier on. Best regards Mike Wilson
Received on Friday, 23 February 2007 15:38:56 UTC