C
C#2y ago
İrşat

Fetch api response status code always 200

.then(function (response) {
if (response.ok) {
success.innerHTML = "SUCCESS";
setTimeout(function() {
location.reload();
}, 1000);
}
else if(response.status === 404){
message.innerHTML = "*User not found*";
}
else{
message.innerHTML = "*Server error*";
}
})
.then(function (response) {
if (response.ok) {
success.innerHTML = "SUCCESS";
setTimeout(function() {
location.reload();
}, 1000);
}
else if(response.status === 404){
message.innerHTML = "*User not found*";
}
else{
message.innerHTML = "*Server error*";
}
})
I am returning things like return new JsonResult(StatusCode(404)); in the back end and I saw it return this. Like I wanted. But I guess I don't know how to work with this result in the javascript.
22 Replies
Teddy
Teddy2y ago
return NotFound();
jcotton42
jcotton422y ago
Oh whoops
Teddy
Teddy2y ago
:p
İrşat
İrşat2y ago
My method is public async Task<JsonResult> UserLogin([FromBody] AccountRead2 account) Is it correct?
jcotton42
jcotton422y ago
Misread 404 as 400 Use NotFound yeah
Teddy
Teddy2y ago
Everything returned from ASP.NET is serialized to JSON by default, is it like a UserDto or something?
İrşat
İrşat2y ago
NotFoundResult cannot be converted into JsonResult it says
Teddy
Teddy2y ago
Yeah, so you'd wrap it in ActionResult<>
jcotton42
jcotton422y ago
The return type should be ActionResult
İrşat
İrşat2y ago
Let's see. I am running it
Teddy
Teddy2y ago
public async Task<IActionResult> UserLogin if you're just returning return Ok() or return NotFound()
İrşat
İrşat2y ago
hell yes it worked thanks And statusCode(530) works I guess I added it for some other thing now
jcotton42
jcotton422y ago
530?
İrşat
İrşat2y ago
custom, 500+ should be server sided errors right?
jcotton42
jcotton422y ago
What are you using 530 to represent?
İrşat
İrşat2y ago
I am creating a jwt for user login. Or there are various places that may be caused by my coding. If this jwt fails, I am sending 530. That's largely to inform me. for development process 530 is site is frozen error I guess. But it shouldn't matter
jcotton42
jcotton422y ago
If the JWT fails?
İrşat
İrşat2y ago
if creating jwt string method fails
Teddy
Teddy2y ago
Why would creating a JWT ever fail?
İrşat
İrşat2y ago
that's why I said it's not for the user. Who knows which one of my fingers may create a disturbance in that method in the next few months. I am leaving for dinner, don't mind me if I can't answer. THANK YOU once more. I would struggle even now
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View