Bloom.Api.ApiRequest.Failed C# (CSharp) Method

Failed() public method

public Failed ( string text ) : void
text string
return void
        public void Failed(string text)
        {
            //Debug.WriteLine(this.Requestinfo.LocalPathWithoutQuery+": "+text);
            _requestInfo.ContentType = "text/plain";
            _requestInfo.WriteError(503,text);
        }

Usage Example

Example #1
0
        public static bool Handle(EndpointRegistration endpointRegistration, IRequestInfo info, CollectionSettings collectionSettings, Book.Book currentBook)
        {
            var request = new ApiRequest(info, collectionSettings, currentBook);

            try
            {
                if (Program.RunningUnitTests)
                {
                    endpointRegistration.Handler(request);
                }
                else
                {
                    var label = "";
                    if (endpointRegistration.DoMeasure && (endpointRegistration.FunctionToGetLabel != null))
                    {
                        label = endpointRegistration.FunctionToGetLabel();
                    }
                    else if (endpointRegistration.DoMeasure)
                    {
                        label = endpointRegistration.MeasurementLabel;
                    }
                    using (endpointRegistration.DoMeasure ? PerformanceMeasurement.Global?.Measure(label) : null)
                    {
                        // Note: If the user is still interacting with the application, openForms could change and become empty
                        var formForSynchronizing = Application.OpenForms.Cast <Form>().LastOrDefault();
                        if (endpointRegistration.HandleOnUIThread && formForSynchronizing != null &&
                            formForSynchronizing.InvokeRequired)
                        {
                            InvokeWithErrorHandling(endpointRegistration, formForSynchronizing, request);
                        }
                        else
                        {
                            endpointRegistration.Handler(request);
                        }
                    }
                }
                if (!info.HaveOutput)
                {
                    throw new ApplicationException(string.Format("The EndpointHandler for {0} never called a Succeeded(), Failed(), or ReplyWith() Function.", info.RawUrl.ToString()));
                }
            }
            catch (System.IO.IOException e)
            {
                var shortMsg = String.Format(L10NSharp.LocalizationManager.GetDynamicString("Bloom", "Errors.CannotAccessFile", "Cannot access {0}"), info.RawUrl);
                var longMsg  = String.Format("Bloom could not access {0}.  The file may be open in another program.", info.RawUrl);
                NonFatalProblem.Report(ModalIf.None, PassiveIf.All, shortMsg, longMsg, e);
                request.Failed(shortMsg);
                return(false);
            }
            catch (Exception e)
            {
                //Hard to reproduce, but I got one of these supertooltip disposal errors in a yellow box
                //while switching between publish tabs (e.g. /bloom/api/publish/android/cleanup).
                //I don't think these are worth alarming the user about, so let's be sensitive to what channel we're on.
                NonFatalProblem.Report(ModalIf.Alpha, PassiveIf.All, "Error in " + info.RawUrl, exception: e);
                request.Failed("Error in " + info.RawUrl);
                return(false);
            }
            return(true);
        }
All Usage Examples Of Bloom.Api.ApiRequest::Failed