public Outcome <HttpReply> Send(HttpRequestSpec spec) { try { var request = CreateRequest(spec); var response = client.SendAsync(request).Result; var descriptor = new HttpReplyStatus ( ProtocolCode: HttpResultCodes.Find((int)response.StatusCode), SystemCode: SystemResultCodes.Success ); var data = response.Content.ReadAsStringAsync().Result; var notification = response.IsSuccessStatusCode ? none <IApplicationMessage>() : some(HttpStatusMessages.ErrorStatus(descriptor, data)); return(success( new HttpReply(descriptor, data), notification.ValueOrDefault(ApplicationMessage.Empty) )); } catch (Exception e) { return(InterpretError(e, spec)); } }
static Outcome <HttpReply> InterpretWebException(WebException we, HttpRequestSpec spec) { try { //If we can successfully retrieve an error response, then whatever //happened is not considered a systemic failure var response = we.Response; if (response == null) { return(SystemFailed(we, spec)); } using (var stream = response.GetResponseStream()) using (var reader = new StreamReader(stream)) { var data = reader.ReadToEnd(); var descriptor = new HttpReplyStatus ( ProtocolCode: response.GetHttpStatusCode(), SystemCode: SystemResultCodes.Success ); return(new Outcome <HttpReply>(true, new HttpReply(descriptor, data), HttpStatusMessages.ErrorStatus(descriptor, data))); } } catch (Exception e) { return(SystemFailed(e, spec)); } }
public HttpServiceResponse(HttpReplyStatus ResultDescriptor, TContent Content) { this.ResultDescriptor = ResultDescriptor; this.Content = Content; }
public HttpReply(HttpReplyStatus Status, string Data) { this.Status = Status; this.Data = Data; }
public HttpStatusDescription(HttpReplyStatus Status, string ErrorResponse) { this.SystemResult = Status.SystemCode; this.ProtocolResult = Status.ProtocolCode; this.ErrorResponse = ErrorResponse; }
public HttpResponse(HttpReplyStatus Result) { this.Result = Result; this.Content = none <C>(); }
public HttpResponse(HttpReplyStatus Result, C Content) { this.Result = Result; this.Content = Content; }
public static IApplicationMessage ErrorStatus(HttpReplyStatus Status, string ErrorResponse) => ApplicationMessage.Error("System Result:@SystemResult; Protocol Result:@ProtocolResult; @ErrorResponse", new HttpStatusDescription(Status, ErrorResponse));