private Response CreateNegotiatedResponse(NancyContext context, IResponseNegotiator responseNegotiator, Exception exception) { HttpServiceError httpServiceError = HttpServiceErrorUtilities.ExtractFromException(exception, HttpServiceErrorDefinition.GeneralError); Negotiator negotiator = new Negotiator(context) .WithStatusCode(httpServiceError.HttpStatusCode) .WithModel(httpServiceError.ServiceErrorModel); return(responseNegotiator.NegotiateResponse(negotiator, context)); }
public static HttpServiceError ExtractFromException(Exception exception, HttpServiceError defaultValue) { HttpServiceError result = defaultValue; if (exception != null) { IHasHttpServiceError exceptionWithServiceError = exception as IHasHttpServiceError; if (exceptionWithServiceError != null) { result = exceptionWithServiceError.HttpServiceError; } } return(result); }