public override byte[] GetResponseForError(Exception e, out string contentType) { contentType = "application/json"; string json = new JsonOperationResponseBase() { Error = e.ToString() }.ToJson(); return(Encoding.UTF8.GetBytes(json)); }
public override void OnOperation(HttpListenerContext context, Authentication authentication) { Arguments arguments = GetArguments(context); ContentType = "application/json"; StatusCode = HttpStatusCode.OK; JsonOperationResponseBase operationResponseBase; if (arguments != null) { operationResponseBase = OnOperation(arguments, authentication); context.Response.ContentType = ContentType; context.Response.StatusCode = (int)StatusCode; } else { StatusCode = HttpStatusCode.BadRequest; operationResponseBase = new JsonOperationResponseBase() { Error = "The provided request was invalid" }; } if (operationResponseBase != null) { HttpStream stream = new HttpStream(context.Response); stream.Send(operationResponseBase.ToJson()); stream.Close(); } else { HttpStream stream = new HttpStream(context.Response); stream.Send("null"); stream.Close(); } }