Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Will Liao 1 post 71 karma points
    Apr 10, 2019 @ 07:33
    Will Liao
    0

    ExceptionMessage is missing from API http Response

    Hi guys,

    I'm new to Umbraco and currently I am working on a data driven Umbraco website.

    User will update the data by using the front end form. The update request will go through the http post and UmbracoApiController to the sql server.

    If something is wrong on the sql server, I would like to return the exception message to the front end.

    here is the method in ApiController:

        [System.Web.Http.HttpPost, System.Web.Http.HttpGet]
        [System.Web.Http.Route("umbraco/ats/loaderapi/UpdateFormData")]
        public IHttpActionResult UpdateFormData([FromBody]Models.TableInfo data)
        {
    
            string connectionStringID = GetPropertyEditorsPreValues();
    
            using (var database = new Database(connectionStringID))
            {
    
                try
                {
                    // do something to the SQL server
                }
                catch (Exception ex)
                {
                    LogHelper.Error(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType, "SQL- Exception", ex);
    
                    return InternalServerError(ex);
                }
            }
    
            return Ok();
        }
    

    here is the function in front end component ts script:

    updateEntryApi(: boolean {
    
        // open edit form dialog
    
        let result: boolean;
    
        let payLoad = JSON.stringify(formParameters);
        let headers = new Headers({ 'Content-Type': 'application/json' });
    
        this.httpmodule.post('/umbraco/ATS/LoaderApi/UpdateFormData', payLoad, { headers: headers }).subscribe(
            data => {
                this.snackbar.open("Success! - Entry Updated", 'Close', { duration: 5000 });
                result = true;
            },
            error => {
                if (!error.ok) {
    
                    this.snackbar.open(error.statusText + " - Error Code: " + error.json().ExceptionMessage, 'Close', { duration: 50000 });
                    result = false;
                }
            });
        return result;
    }
    

    I tried to convert the error Response to json and display the ExceptionMessage in the Response body. The weird thing is, the error.json().ExceptionMessage is working fine in my visual studio iis express. And I published it on the server, if I open the page on the sever, error.json().ExceptionMessage is still working fine. But if I open the web page hosted by the server, from another PC, the error.json().ExceptionMessage is blank.

    here is the Response I expected (in visual studio iis express environment): http response I expected

    What I got(open the web page hosted by the server, from another PC,):

    Response only contains a Message

    I hope I explained the problem clearly. I scratched my head for a day and couldn't find out the reason.

    Thanks a lot!

Please Sign in or register to post replies

Write your reply to:

Draft