internal static Action <Stream> HandleBeforeWritingException(Exception exception, IDataService service) { string str; Encoding encoding; string str2; Version responseVersion = null; DataServiceHostWrapper host = service.OperationContext.Host; TryGetResponseFormatForError(service, host, RequestDescription.DataServiceDefaultResponseVersion, out str, out encoding, out str2, out responseVersion); bool verboseResponse = (service.Configuration != null) ? service.Configuration.UseVerboseErrors : false; HandleExceptionArgs args = new HandleExceptionArgs(exception, false, str2, verboseResponse); service.InternalHandleException(args); host.ResponseVersion = responseVersion.ToString(2) + ";"; host.ProcessException(args); Action <Stream> action = ProcessBenignException(exception, service); ODataFormat atom = ODataFormat.Atom; if (WebUtil.GetContentFormat(str) == ContentFormat.VerboseJson) { atom = ODataFormat.VerboseJson; } return(action ?? CreateErrorSerializer(atom, args, encoding)); }