Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/sql-server-2005/2.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 角度HTTP请求从服务器返回错误_Javascript_Angular_Typescript - Fatal编程技术网

Javascript 角度HTTP请求从服务器返回错误

Javascript 角度HTTP请求从服务器返回错误,javascript,angular,typescript,Javascript,Angular,Typescript,我在angular项目中有一个来自的注册,它将新用户的详细信息发送到服务器并 也应该从它那里获得响应,但它返回一个错误 这是注册服务代码: const httpOptions = { headers: new HttpHeaders({ "Content-Type": "application/json" }) }; @Injectable({ providedIn: "root" }) export class RegisterService { constructo

我在angular项目中有一个来自的注册,它将新用户的详细信息发送到服务器并 也应该从它那里获得响应,但它返回一个错误

这是注册服务代码:

const httpOptions = {
  headers: new HttpHeaders({
    "Content-Type": "application/json"
  })
};

@Injectable({
  providedIn: "root"
})
export class RegisterService {
  constructor(private http: HttpClient) {}

  addUser(user: registerForm): Observable<registerForm> {
    return this.http.post<registerForm>(
      `http://localhost:3000/users/register`,
      user,
      httpOptions
    );
  }
} 
这就是我得到的错误:

HttpErrorResponse {headers: HttpHeaders, status: 500, statusText: "Internal Server Error", url: "http://localhost:3000/users/register", ok: false, …}
headers: HttpHeaders {normalizedNames: Map(0), lazyUpdate: null, lazyInit: ƒ}
status: 500
statusText: "Internal Server Error"
url: "http://localhost:3000/users/register"
ok: false
name: "HttpErrorResponse"
message: "Http failure response for http://localhost:3000/users/register: 500 Internal Server Error"
error: "levitomer1996@gmail.com is already taken by another user."
__proto__: HttpResponseBase
这是状态为200时的错误:
HttpErrorResponse{headers:HttpHeaders,状态:200,状态文本:“OK”,url:http://localhost:3000/users/register“,ok:false,…}
Header:HttpHeaders{normalizedNames:Map(0),lazyUpdate:null,lazyInit:ƒ}
现状:200
状态文本:“确定”
url:“http://localhost:3000/users/register"
好:错
名称:“HttpErrorResponse”
消息:“在解析的过程中Http失败。”http://localhost:3000/users/register"
错误:{error:SyntaxError:XML的JSON.parse()位置0处的JSON中意外的标记O
也许我遗漏了什么?在过去,我常常通过Fetch,然后catch发送请求并获得响应。
我不明白在哪里可以控制客户端服务器的响应…

错误代码是500,这意味着错误实际上是服务器端的。 错误是: levitomer1996@gmail.com已被另一个用户使用

尝试使用其他电子邮件注册。
如果这不起作用,请向我们显示后端注册码

更改
电子邮件id
可能是什么?错误消息非常清楚。``HttpErrorResponse{headers:HttpHeaders,status:200,statusText:“OK”,url:,OK:false,}headers:HttpHeaders{normalizedNames:Map(0),lazyUpdate:null,lazyInit:ƒ}状态:200 statusText:“OK”url:“ok:false name:“HttpErrorResponse”消息:“解析过程中Http失败”错误:{error:SyntaxError:JSON中位于JSON位置0处的意外标记O.parse()位于XML"这是它在状态为200Ok perfect时发送的错误,现在您的后端没有错误,但前端需要一个json响应。相反,您的后端返回了其他内容。您可以使用浏览器开发工具中的“网络”选项卡检查您的后端服务器返回的响应是什么吗?它返回XHRI需要查看e文本格式的响应内容,以帮助您进一步了解它实际上只通过expressJS res.sendStatus(200)发送状态200;如果它出错,它将发送状态500,并显示错误消息res.status(500).send(err);
HttpErrorResponse {headers: HttpHeaders, status: 500, statusText: "Internal Server Error", url: "http://localhost:3000/users/register", ok: false, …}
headers: HttpHeaders {normalizedNames: Map(0), lazyUpdate: null, lazyInit: ƒ}
status: 500
statusText: "Internal Server Error"
url: "http://localhost:3000/users/register"
ok: false
name: "HttpErrorResponse"
message: "Http failure response for http://localhost:3000/users/register: 500 Internal Server Error"
error: "levitomer1996@gmail.com is already taken by another user."
__proto__: HttpResponseBase
This is the error when status is 200:
HttpErrorResponse {headers: HttpHeaders, status: 200, statusText: "OK", url: "http://localhost:3000/users/register", ok: false, …}
headers: HttpHeaders {normalizedNames: Map(0), lazyUpdate: null, lazyInit: ƒ}
status: 200
statusText: "OK"
url: "http://localhost:3000/users/register"
ok: false
name: "HttpErrorResponse"
message: "Http failure during parsing for http://localhost:3000/users/register"
error: {error: SyntaxError: Unexpected token O in JSON at position 0 at JSON.parse (<anonymous>) at XML