Sending HTTP status codes can get tricky. If you are using a JavaScript client, for JSONP callbacks to work you MUST always send a status of 200. This is why REST API sends a status code of 200 even when your request failed, but adds the actual HTTP status in a error JSON object. You can choose to do the same. Otherwise you can set a custom HTTP header using responseProperties.
JSONObject jobj = new JSONObject(); jobj.put("X-HTTP-Status", "500, An error occured when generating the image."); responseProperties[0] = jobj.toString();
responseProperties = "{ \"Content-Type\" : \"image/png\", \"X-HTTP-Status\" : \"500 - An error occurred while generating the image.\" }";
If your SOE is in .NET you will have to construct the jsonified string yourself.Essentially it would be: responseProperties = "{ \"Content-Type\" : \"image/png\", \"X-HTTP-Status\" : \"500 - An error occurred while generating the image.\" }";
RestOperation findNearFeatsOp = new RestOperation("GetImage", new string[0] , new string[] { "img" }, GetImage); .................. private byte[] GetImage(System.Collections.Specialized.NameValueCollection boundVariables, ESRI.ArcGIS.SOESupport.JsonObject operationInput, string outputFormat, string requestProperties, out string responseProperties) { responseProperties = "{\"Content-Type\" : \"image/png\",\"X-HTTP-Status\" : \"404 - Could not find the image requested.\"}"; return null; }
private byte[] GetImage(System.Collections.Specialized.NameValueCollection boundVariables, ESRI.ArcGIS.SOESupport.JsonObject operationInput, string outputFormat, string requestProperties, out string responseProperties) { try { ........ }catch(Exception e) { //Log your exception and throw it so that the REST handler intercepts your exception // and treats it as a HTTP 500. throw e; } }
Aangemelde leden kunnen berichten plaatsen, updates volgen en meer. Nieuw hier? Registreer een gratis account.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.