Base solution for your next web application
Ends in:
01 DAYS
01 HRS
01 MIN
01 SEC
Open Closed

UserFriendlyException not handled correctly by Angular App #3984


User avatar
0
ajayak created

I have created the following function:

public async Task<RedirectResult> Install(string shop)
        {
            if (!await GenericHelper.IsValidShopDomainAsync(shop))
            {
                throw new UserFriendlyException(L("PP_Invalid_Shopify_Url"));
            }
            return new RedirectResult(_shopifyManager.GetAuthRedirectUrl(shop));
        }

In the code block, when user hits exception, I am getting following error on client: ![image]( <a class="postlink" href="https://imgur.com/a/zqhXl">https://imgur.com/a/zqhXl</a> )

2:5000/api/services/app/Shopify/Install?shop=asd:1 GET <a class="postlink" href="http://localhost:5000/api/services/app/Shopify/Install?shop=asd">http://localhost:5000/api/services/app/ ... l?shop=asd</a> 500 (Internal Server Error) sales-channel:1 Failed to load <a class="postlink" href="http://localhost:5000/api/services/app/Shopify/Install?shop=asd">http://localhost:5000/api/services/app/ ... l?shop=asd</a>: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:4200' is therefore not allowed access. The response had HTTP status code 500. scripts.bundle.js:44583 WARN: scripts.bundle.js:44583 Content-Type is not sent! Subscriber.js:238 HTTP error: 0, webpackJsonp.../../../../rxjs/Subscriber.js.SafeSubscriber.__tryOrUnsub @ Subscriber.js:238 ...


3 Answer(s)
  • User Avatar
    0
    aaron created
    Support Team

    No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:4200' is therefore not allowed access.

    and your other topic RedirectResult Causes Server Error:

    No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'null' is therefore not allowed access.

    To allow CORS, see:

  • User Avatar
    0
    ajayak created

    Hi aaron,

    CORS is configured correctly in the app as

    services.AddCors(options =>
                {
                    options.AddPolicy(DefaultCorsPolicyName, builder =>
                    {
                            .AllowAnyOrigin()
                            .AllowAnyHeader()
                            .AllowAnyMethod();
                    });
                });
    

    and used as

    app.UseAbp(options =>
                {
                    options.UseAbpRequestLocalization = false; //used below: UseAbpRequestLocalization
                });
    
                app.UseCors(DefaultCorsPolicyName); //Enable CORS!
    

    All the other app services are working fine. Only getting Internal Server error on line:

    throw new UserFriendlyException(L("PP_Invalid_Shopify_Url"));
    

    In browser, it says CORS error but I suspect it to be something else.

  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi @ajayak,

    it is because you are returning RedirectResult I think. You should return JsonResult to angular.