TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Dawood Abbas
NA
32
3k
Mix angularjs http error handling and MVC custom page error?
Apr 2 2020 10:08 AM
How to Mix angularjs http error handling and MVC custom page error?
I need to manage page not found and server propblem erros by redirect to my own custom error pages, so I done this by following, and its working fine.
web.config
"On"
>
"400"
redirect=
"~/Error/Error400"
/>
"404"
redirect=
"~/Errors/Error404"
/>
"403"
redirect=
"~/Error/Error403"
/>
"500"
redirect=
"~/Errors/Error500"
/>
so now when I need to get the angularjs http erros like 404 by follwing code in which passing wrong methode (GetDetai) which is not available in controller (actual is 'GetDetails').
$http({
method:
'GET'
,
url:
'/Admin/Dashboard/GetDetai'
,
headers: {
"Content-Type"
:
"application/json"
}
}).then(
function
(result) {
console.log(result);
$scope.GetCustomer = result.data;
},
function
(reason) {
console.log(reason);
if
(reason.status ==
'404'
) {
console.log(
'Invalid Methode/Url.'
);
}
else
if
(reason.status ==
'505'
) {
console.log(
'Internal server error.'
);
}
});
then its not ctaching the 400 error in error function, its going into then function and displaying below
First Console log
{data: "
↵
↵
↵>
↵
<
html
>
↵
<
head
>
↵
<
meta
c…white;"
>
Go Back To Home
a
>
↵
body
>
↵
html
>
↵
↵", status: 200, config: {…}, statusText: "OK", headers: ƒ, …}
data: "
↵
↵
↵>
↵
<
html
>
↵
<
head
>
↵
<
meta
charset
=
"utf-8"
/>
↵
<
title
>
title
>
↵
<
style
>
↵ body {
↵ display: inline-block;
↵ background: #00AFF9 url(https://cbwconline.com/IMG/Codepen/Unplugged.png) center/cover no-repeat;
↵ height: 100vh;
↵ margin: 0;
↵ color: white;
↵ }
↵
↵ h1 {
↵ margin: .8em 3rem;
↵ font: 4em Roboto;
↵ }
↵
↵ p {
↵ display: inline-block;
↵ margin: .2em 3rem;
↵ font: 2em Roboto;
↵ }
↵
style
>
↵
head
>
↵
<
body
>
↵
<
h1
>
Whoops!
h1
>
↵
<
p
>
Something went wrong
p
>
<
br
/>
<
br
/>
↵
↵
<
a
href
=
"/Home/Index"
style
=
"color:white;"
>
Go Back To Home
a
>
↵
body
>
↵
html
>
↵
↵"
status: 200
headers: ƒ (name)
config: {method: "GET", transformRequest: Array(1), transformResponse: Array(1), jsonpCallbackParam: "callback", paramSerializer: ƒ, …}
statusText: "OK"
xhrStatus: "complete"
__proto__: Object
But when I commented/removed that web.config custom error code then this angularjs http call error function working properly, getting expected 404 error.
So How to manag these both kind of errors properly with non dipendencies and non effect on other codes?
Reply
Answers (
0
)
Search Domain Name if exist in google
Dropdownlist not hold selected value while use pagination