Good day,
How can I override / overload the abp.ng.http.showError method in my angular project?
After reading couple of post, I have tried the following without success:
added "../node_modules/abp-web-resources/Abp/Framework/scripts/libs/angularjs/abp.ng.js" to the .angular-cli.json file
Created a js file with the following code:
var abp = abp || {};
(function () {
abp.ng.http.showError = function (error) {
alert("am in!!");
}
})();
- Added js file to the .angular-cli.json file.
For testing, I have added an alert in the showError method of "\node_modules\abp-ng2-module\src\abpHttp.ts" and alert was showing for all error messages. Should this method be overwritten instead of the one in the js file? .
showError(error: IErrorInfo): any {
alert("am in");
if (error.details) {
return this._messageService.error(error.details, error.message || this.defaultError.message);
} else {
return this._messageService.error(error.message || this.defaultError.message);
}
}
14 Answer(s)
-
0
Hi @dreamsmiths,
"abp.ng.http" is used for AngularJs not for Angular. So, if you could tell us what you are trying to achieve, we can make some suggestions.
-
0
Hi
I did edit the post, not sure if you saw it.
"For testing, I have added an alert in the showError method of "\node_modules\abp-ng2-module\src\abpHttp.ts" and alert was showing for all error messages. Should this method be overwritten instead of the one in the js file? .
showError(error: IErrorInfo): any { alert("am in"); if (error.details) { return this._messageService.error(error.details, error.message || this.defaultError.message); } else { return this._messageService.error(error.message || this.defaultError.message); } }
"
I want to catch a specific UserFriendlyException and act on it.
-
0
Hi,
Sorry, I missed that. You can't override it like that because next time when you install packages, your changes will be gone. The proper way is to define your own Angular HttpInterceptor and use it <a class="postlink" href="https://angular.io/api/common/http/HttpInterceptor">https://angular.io/api/common/http/HttpInterceptor</a>.
-
0
Hi,
Yes I am aware of that, I was just placing the alert in there to see if that's the method being used. I will look into http interceptors.
Thanks in a million.
-
0
Hi,
Yes I am aware of that, I was just placing the alert in there to see if that's the method being used. I will look into http interceptors.
Thanks in a million.
-
0
Hi
I am running into some issues in using the interceptors.
Is there any way to override/ replace the showError function with my own implementation?
Snippet of current code:
showError(error: IErrorInfo): any { alert("am in"); if (error.details) { return this._messageService.error(error.details, error.message || this.defaultError.message); } else { return this._messageService.error(error.message || this.defaultError.message); } }
Regards David
-
0
@dreamsmiths not that I know. What is the problem ? Maybe we could help.
-
0
We need to upgrade a lot of packages to be able to use interceptors, including swagger etc. This is giving lots of issues, and have spent most of the day struggling with upgrades, and don't really want to take the risk in upgrading.
The thing we want to do is:
- Server side we currently throw a specific UserFriendlyException (this error can be thrown from multiple API calls )
- Clientside we want to check this UserFriendlyException at a global level, and if this matches a specific String, we want to log the user out.
There must be a way to replace/overriding the "showError" method, without changing the "\node_modules\abp-ng2-module\src\abpHttp.ts" file?
-
0
Hi,
At the end,
abp.message.error
function is used. You can replace this function with your own code and see if you can handle it like you want.
-
0
I don't see this in the "\node_modules\abp-ng2-module\src\abpHttp.ts" file:
abp.message.error
Where would I be able to change it, without changing the node_module files?
-
0
I don't see this in the "\node_modules\abp-ng2-module\src\abpHttp.ts" file:
abp.message.error
Where would I be able to change it, without changing the node_module files? Can you please show how to do this?
-
0
Hi,
It is defined in node_modules\abp-web-resources\Abp\Framework\scripts\abp.js and then overriden in node_modules\abp-web-resources\Abp\Framework\scripts\libs\abp.sweet-alert.js
-
0
Hi
How would you replace this function you mentioned, without changing the "\node_modules\abp-ng2-module\src\abpHttp.ts" file?
Regards
-
0
Just create a new js file and include it into angular.json (or .angular-cli.json for Angular v5) after abp.sweet-alert.js. It will work after abp.sweet-alert.js and will override the function.