Fetch api response status code always 200
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
return NotFound();
Use BadRequest https://docs.microsoft.com/en-us/dotnet/api/microsoft.aspnetcore.mvc.controllerbase.badrequest?view=aspnetcore-6.0
ControllerBase.BadRequest Method (Microsoft.AspNetCore.Mvc)
Creates an BadRequestResult that produces a Status400BadRequest response.
Oh whoops
:p
My method is
public async Task<JsonResult> UserLogin([FromBody] AccountRead2 account)
Is it correct?Misread 404 as 400
Use NotFound yeah
Everything returned from ASP.NET is serialized to JSON by default, is it like a
UserDto
or something?NotFoundResult cannot be converted into JsonResult it says
Yeah, so you'd wrap it in
ActionResult<>
The return type should be ActionResult
Let's see. I am running it
public async Task<IActionResult> UserLogin
if you're just returning return Ok()
or return NotFound()
hell yes
it worked thanks
And statusCode(530) works I guess
I added it for some other thing now
530?
custom, 500+ should be server sided errors right?
What are you using 530 to represent?
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
If the JWT fails?
if creating jwt string method fails
Why would creating a JWT ever fail?
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•3y ago
Message Not Public
Sign In & Join Server To View