Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/33.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript获取-读取错误的请求响应时出现问题_Javascript_Node.js_Fetch - Fatal编程技术网

Javascript获取-读取错误的请求响应时出现问题

Javascript获取-读取错误的请求响应时出现问题,javascript,node.js,fetch,Javascript,Node.js,Fetch,我有一个asp.net核心服务器,在本例中,它被故意发送了一个fetch,该fetch会产生错误的请求响应 以下是控制器的一部分,用于: [HttpPost] [AllowAnonymous] public async Task<IActionResult> Get([FromBody] LoginViewModel model) { MembershipContext _userContext = _tokenService.Vali

我有一个asp.net核心服务器,在本例中,它被故意发送了一个fetch,该fetch会产生错误的请求响应

以下是控制器的一部分,用于:

    [HttpPost]
    [AllowAnonymous]
    public async Task<IActionResult> Get([FromBody] LoginViewModel model)
    {
        MembershipContext _userContext = _tokenService.ValidateUser(model.Email, model.Password);

        if (_userContext.Principal == null)
        {
            logger.LogInformation($"Invalid username ({model.Email}) or password ({model.Password})");
            return BadRequest("Invalid credentials"); // Here..
        }...

如何检查响应中的“无效凭据”?我可以检查是否有错误响应,但最好检查服务器实际发送的响应。

您不能。在Well看到的答案基本上回答了我的问题:(我会处理这个问题。)那么,在坏请求中添加“无效凭据”或其他内容的机会有什么意义呢?如果你无法访问它……你不能。在Well看到的答案基本上回答了我的问题:(我将对此进行处理..因此,如果您无法访问该请求,那么实际添加添加“无效凭据”或其他错误请求的机会有什么意义。。
    // Lets do a fetch!
    const task = fetch("/api/jwt", {
        method: "POST",
        body: JSON.stringify(this.userLogin),
        headers: new Headers({ 'content-type': 'application/json' })
    })
        .then(response => {
            console.log("STATUS: ", response.status, response.statusText)
            return response.json()})
        .then(data => {
            console.log("got here", data)
            localStorage.setItem(this.TOKEN_KEY, JSON.stringify(data));
        })
        .then(() => {... so on..