我在Angular应用程序中遇到了同样的问题。我在应用程序中使用了RocketChat REST API,并且尝试使用rooms.createDiscussion
,但出现以下错误。
ERROR Error: Uncaught (in promise): HttpErrorResponse: {"headers":{"normalizedNames":{},"lazyUpdate":null},"status":200,"statusText":"OK","url":"myurl/rocketchat/api/v1/rooms.createDiscussion","ok":false,"name":"HttpErrorResponse","message":"Http failure during parsing for myrul/rocketchat/api/v1/rooms.createDiscussion","error":{"error":{},"text":"
我已经尝试了几项诸如更改的操作,responseType: 'text'
但都无济于事。最后,我能够发现问题出在我的RocketChat安装上。如RocketChat更改日志中所述,该API rooms.createDiscussion
是在1.0.0版中引入的,很遗憾,我使用的是较低版本。
我的建议是在花费时间修复Angular代码中的错误之前,检查REST API是否正常工作。我用curl
命令来检查。
curl -H "X-Auth-Token: token" -H "X-User-Id: userid" -H "Content-Type: application/json" myurl/rocketchat/api/v1/rooms.createDiscussion -d '{ "prid": "GENERAL", "t_name": "Discussion Name"}'
在那里,我得到了无效的HTML作为响应。
<!DOCTYPE html>
<html>
<head>
<meta name="referrer" content="origin-when-crossorigin">
<script>/* eslint-disable */
'use strict';
(function() {
var debounce = function debounce(func, wait, immediate) {
代替如下的有效JSON响应。
{
"discussion": {
"rid": "cgk88DHLHexwMaFWh",
"name": "WJNEAM7W45wRYitHo",
"fname": "Discussion Name",
"t": "p",
"msgs": 0,
"usersCount": 0,
"u": {
"_id": "rocketchat.internal.admin.test",
"username": "rocketchat.internal.admin.test"
},
"topic": "general",
"prid": "GENERAL",
"ts": "2019-04-03T01:35:32.271Z",
"ro": false,
"sysMes": true,
"default": false,
"_updatedAt": "2019-04-03T01:35:32.280Z",
"_id": "cgk88DHLHexwMaFWh"
},
"success": true
}
因此,在更新到最新的RocketChat之后,我可以使用提到的REST API。