Base solution for your next web application
Open Closed

Override default defaultError404 AbpHttpConfiguration #4719


User avatar
0
henriksorensen created

Hi

I am calling a external rest service which returns a 404 error if query is not found. I would like to handle this error (and other errors) and not the default defaultError404 AbpHttpConfiguration.

this.ServiceProxy.apiV1Post(input)
                    .finally(() => { this.saving = false; })
                    .subscribe(() => {
                        this.notify.info(this.l('SavedSuccessfully'));
                        this.close();
                        this.modalSave.emit(null);
                    });

How to display custom error and prevent defaultError404 being called?

We call the exteranl service via serviceproxy generated by nswag.
It is a angular 5 +.net core project

I seen the "abpHandleError" setting but that seems to relate to a jquery project. Correct me if i am wrong.

Thanks, Henrik


8 Answer(s)
  • User Avatar
    0
    ismcagdas created
    Support Team

    @henriksorensen if you can upgrade to abp-ng2-module's v2.0, then you can define a Angular Http Interceptor and handle errors as you like.

    Here is the Angular's documentation <a class="postlink" href="https://angular.io/api/common/http/HttpInterceptor">https://angular.io/api/common/http/HttpInterceptor</a>. Here is the related issue on AspNet Zero which we upgraded to abp-ng2-module, <a class="postlink" href="https://github.com/aspnetzero/aspnet-zero-core/issues/703">https://github.com/aspnetzero/aspnet-ze ... issues/703</a>.

    Let me know if you have any problems.

  • User Avatar
    0
    henriksorensen created

    @ismcagdas , thanks. I have upgraded abp-ng2-module to v2. I get some errors.

    In root.modul.ts "ABP_HTTP_PROVIDER" is not found when

    import { AbpModule , ABP_HTTP_PROVIDER } from '@abp/abp.module';
    
    providers: [
            ABP_HTTP_PROVIDER,
    

    In tenant-settings.component.ts and change-profile-picture-modal.component.ts should i replace 7

    import { IAjaxResponse } from '@abp/abpHttp'; with
    import { HttpInterceptor } from '@angular/common/http';
    

    and replace const ajaxResponse = <IAjaxResponse>JSON.parse(response); with HttpInterceptor?

    Can I download the above files somewhere or can past what to change. I am unsure what to change.

    Thanks, Henrik

  • User Avatar
    0
    ismcagdas created
    Support Team

    You can see necessary changes in this commit <a class="postlink" href="https://github.com/aspnetzero/aspnet-zero-core/commit/5e1e9f8b7bfb505012b18ea98d4cff3d8e415412">https://github.com/aspnetzero/aspnet-ze ... 3d8e415412</a>.

  • User Avatar
    0
    henriksorensen created

    @ismcagdas

    Thanks. I have made the necessary changes. The solution builds and i can go to localhost:4200 and i see the spinner but then nothing happens. In chrome developer the last successful request is to GetCurrentLoginInformations, then it hangs at <a class="postlink" href="ws://localhost:4200/sockjs-node/450/g15t5ui3/websocket">ws://localhost:4200/sockjs-node/450/g15t5ui3/websocket</a>.

  • User Avatar
    0
    ismcagdas created
    Support Team

    @henriksorensen is your service-proxies.ts file changed ? If not, please regenerate it using "../angular/nswag/refresh.bat".

    Also, don't forget to modify service-proxies.module.ts just like in my commit.

  • User Avatar
    0
    henriksorensen created

    @ismcagdas

    Yes I have regenerate service-proxies by doing "../angular/nswag/refresh.bat" and have also modified service-proxies.module.ts like your commit.

  • User Avatar
    0
    henriksorensen created

    @ismcagdas

    Just want to let you know I have fixed my upgrade problem. Did a upgrade from 5.1.0 to 5.2.0.

    Thanks, Henrik

  • User Avatar
    0
    alper created
    Support Team

    congrats ;)