# 错误排查 (/zh-CN/realtime-media/rtm/build/troubleshooting/harmonyos)
> For AI agents: see the complete documentation index at [llms.txt](/llms.txt).
## 开启本地日志 [#开启本地日志-3]
当你的应用处于开发、测试阶段时,你可能需要 SDK 输出更详细的信息来定位并修复问题。你可以在初始化 RTM 实例的时候通过设置 `RtmConfig` 中的 `RtmLogConfig` 来开启日志输出并设置日志信息等级,之后即可在 IDE 中查看日志信息。
```typescript
import { RtmClient, RtmConfig, RtmLogConfig, RtmLogLevel } from '@shengwang/rtm-full';
// Configure log settings
const logConfig: RtmLogConfig = {
filePath: 'your_log_path',
fileSizeInKB: 10240, // 10MB
level: RtmLogLevel.INFO
};
// Create RTM configuration
const config: RtmConfig = {
appId: 'your_appid',
userId: 'your_userid',
logConfig: logConfig
};
try {
const rtmClient = new RtmClient(config);
console.log('RTM Client initialized successfully');
} catch (error) {
console.error('Failed to create RTM client:', error);
}
```
`level` 字段可以设置为 `RtmLogLevel.INFO`、`RtmLogLevel.WARN`、`RtmLogLevel.ERROR`、`RtmLogLevel.FATAL`、`RtmLogLevel.NONE` 五个等级之一,其中 `RtmLogLevel.INFO` 输出最详细的日志信息,`RtmLogLevel.NONE` 不输出日志信息。
:::info[信息]
当你的应用上线时,请将日志信息等级设置为 `INFO`。
:::
## 错误码对照表 [#错误码对照表-3]
| 错误码 | 错误描述 | 原因及解决方法 |
| --- | --- | --- |
| `0` | | 正确调用。 |
| `-10001` | | SDK 未初始化。请在调用 `RtmClient` 方法初始化 RTM 实例后再执行其他操作。 |
| `-10002` | | 用户未登录 RTM 系统、掉线超时或者主动退出登录后调用 API。请先登录 RTM 系统。 |
| `-10003` | | [error-codes-android-ios-swift-cpp-unity-harmonyos-html-0-4-2 details](#table-slot-error-codes-android-ios-swift-cpp-unity-harmonyos-html-0-4-2-2) |
| `-10005` | | 无效 Token。检查 Token Provider 是否生成 RTM Token。 |
| `-10006` | `INVALID_USER_ID` | [error-codes-android-ios-swift-cpp-unity-harmonyos-html-0-6-2 details](#table-slot-error-codes-android-ios-swift-cpp-unity-harmonyos-html-0-6-2-2) |
| `-10007` | | SDK 初始化失败。请重新调用 `RtmClient` 方法进行初始化。 |
| `-10008` | | [error-codes-android-ios-swift-cpp-unity-harmonyos-html-0-8-2 details](#table-slot-error-codes-android-ios-swift-cpp-unity-harmonyos-html-0-8-2-2) |
| `-10009` | | Token 过期失效。你需要调用 `renewToken` 重新获取 Token。 |
| `-10010` | | 服务器资源受限。建议重新登录。 |
| `-10011` | | 登录超时。你需要检查当前网络是否稳定并切换到稳定网络环境中。如果你的网络处于内网环境,请检查你的防火墙是否配置了正确的域名和端口,详见[防火墙白名单设置](/zh-CN/realtime-media/rtm/build/rtm-initialization/application-setup#防火墙白名单设置)。 |
| `-10012` | | [error-codes-android-ios-swift-cpp-unity-harmonyos-html-0-12-2 details](#table-slot-error-codes-android-ios-swift-cpp-unity-harmonyos-html-0-12-2-2) |
| `-10013` | | [error-codes-android-ios-swift-cpp-unity-harmonyos-html-0-13-2 details](#table-slot-error-codes-android-ios-swift-cpp-unity-harmonyos-html-0-13-2-2) |
| `-10014` | | 参数无效。检查你填写的参数是否正确。 |
| `-10015` | | 没有 RTM 服务权限。检查控制台是否开通 RTM 服务。 |
| `-10016` | | App ID 不一致。检查初始化、登录、加入频道的 App ID 是否一致。 |
| `-10017` | | 重复操作。 |
| `-10018` | | 重复调用 `release` 方法释放 `RtmClient` 实例或重复调用 `release` 释放 `StreamChannel` 实例。 |
| `-10019` | | [error-codes-android-ios-swift-cpp-unity-harmonyos-html-0-19-2 details](#table-slot-error-codes-android-ios-swift-cpp-unity-harmonyos-html-0-19-2-2) |
| `-10020` | | [error-codes-android-ios-swift-cpp-unity-harmonyos-html-0-20-2 details](#table-slot-error-codes-android-ios-swift-cpp-unity-harmonyos-html-0-20-2-2) |
| `-10021` | `OPERATION_RATE_EXCEED_LIMITATION` | API 调用频率超过限制。各 API 的配额见[API 使用限制](/zh-CN/realtime-media/rtm/reference/usage-limits-and-errors/api-limits)。 |
| `-10022` | `SERVICE_NOT_SUPPORTED` | 服务类型不支持。请检查你在 `RtmServiceType` 中设置的服务类型是否正确。该错误码仅适用于私有化部署功能。 |
| `-10023` | | [error-codes-android-ios-swift-cpp-unity-harmonyos-html-0-23-2 details](#table-slot-error-codes-android-ios-swift-cpp-unity-harmonyos-html-0-23-2-2) |
| `-10024` | | 私有化部署参数设置无效。请检查你在 `RtmPrivateConfig` 中设置的服务类型和服务器地址是否有效。 |
| `-10025` | `NOT_CONNECTED` | 未连接 RTM 服务器。请确认服务连接可用后再调用相关 API。 |
| `-10026` | | 更新 Token 超时。 |
| `-11001` | | [error-codes-android-ios-swift-cpp-unity-harmonyos-html-0-27-2 details](#table-slot-error-codes-android-ios-swift-cpp-unity-harmonyos-html-0-27-2-2) |
| `-11002` | | [error-codes-android-ios-swift-cpp-unity-harmonyos-html-0-28-2 details](#table-slot-error-codes-android-ios-swift-cpp-unity-harmonyos-html-0-28-2-2) |
| `-11003` | | 订阅该 Topic 人数超出限制。 |
| `-11004` | | 共频道模式下,RTM 释放了 Stream Channel。 |
| `-11005` | | 创建的频道数量或订阅的频道数量超出限制。详见 [API 调用限制](/zh-CN/realtime-media/rtm/reference/usage-limits-and-errors/api-limits)。 |
| `-11006` | | 频道不可用。请重新创建 Stream Channel 或重新订阅 Message Channel。 |
| `-11007` | | [error-codes-android-ios-swift-cpp-unity-harmonyos-html-0-33-2 details](#table-slot-error-codes-android-ios-swift-cpp-unity-harmonyos-html-0-33-2-2) |
| `-11008` | | [error-codes-android-ios-swift-cpp-unity-harmonyos-html-0-34-2 details](#table-slot-error-codes-android-ios-swift-cpp-unity-harmonyos-html-0-34-2-2) |
| `-11009` | | 无效消息。检查消息类型是否合法,RTM 只支持字符串或二进制类型消息。 |
| `-11010` | | [error-codes-android-ios-swift-cpp-unity-harmonyos-html-0-36-2 details](#table-slot-error-codes-android-ios-swift-cpp-unity-harmonyos-html-0-36-2-2) |
| `-11011` | | [error-codes-android-ios-swift-cpp-unity-harmonyos-html-0-37-2 details](#table-slot-error-codes-android-ios-swift-cpp-unity-harmonyos-html-0-37-2-2) |
| `-11012` | | Stream Channel 功能未开通,当前不可用。检查控制台是否已开启 Stream Channel 功能。 |
| `-11013` | | 未订阅该 Topic。 |
| `-11014` | | Topic 数量超出限制。 |
| `-11015` | | 加入该 Topic 失败。检查已加入 Topic 数量是否超出限制。 |
| `-11016` | | 未加入该 Topic。未加入 Topic 就发送消息,你需要先加入 Topic。 |
| `-11017` | | 该 Topic 不存在。检查 Topic 名是否错误。 |
| `-11018` | | Topic 中的 `meta` 参数无效。检查 `meta` 参数是否超出 256 字节的限制。 |
| `-11019` | | 频道订阅超时。检查连接是否断开。 |
| `-11020` | | 频道订阅操作太频繁。请确保 5 秒内对同一频道的订阅操作不超过 2 次。 |
| `-11021` | | 频道订阅失败。检查已订阅频道数量是否超出限制。 |
| `-11022` | | 取消频道订阅失败。检查连接是否断开。 |
| `-11023` | | [error-codes-android-ios-swift-cpp-unity-harmonyos-html-0-49-2 details](#table-slot-error-codes-android-ios-swift-cpp-unity-harmonyos-html-0-49-2-2) |
| `-11024` | | 消息发布失败。检查连接是否断开。 |
| `-11026` | | 消息发布超时。检查连接是否断开。 |
| `-11027` | | SDK 与 RTM 服务器断开连接。请重新登录。 |
| `-11028` | | 离开频道失败。检查连接是否断开。 |
| `-11029` | | Custom type 长度溢出。`customType` 字段长度需要在 32 个字符以内。 |
| `-11030` | | `customType` 字段无效。检查 `customType` 字段是否包含非法字符。 |
| `-11031` | | 消息类型不支持。 |
| `-11032` | | Presence 服务未就绪。请重新加入 Stream Channel 或重新订阅 Message Channel。 |
| `-11033` | | [error-codes-android-ios-swift-cpp-unity-harmonyos-html-0-58-2 details](#table-slot-error-codes-android-ios-swift-cpp-unity-harmonyos-html-0-58-2-2) |
| `-11034` | | 加入频道操作已取消。调用 `join` 方法后,如果你在收到调用结果之前再次调用该方法,则前一次的调用操作会被取消,SDK 会执行后一次的调用。 |
| `-11035` | | 接收端已下线,且消息成功保存至历史消息,待接收端上线后可查看消息。 |
| `-11036` | | 接收端已下线,但历史消息存储失败。 |
| `-11037` | | 消息成功发送到接收端,但历史消息存储失败。 |
| `-11040` | `CHANNEL_SUBSCRIBE_CANCELED` | 订阅频道操作已取消。调用 `subscribe` 后,如果在收到结果前调用 `unsubscribe` 打断订阅,会返回该错误。 |
| `-12001` | | Storage 操作失败。 |
| `-12002` | | Storage Metadata Item 数量超出限制。 |
| `-12003` | | 无效 Metadata Item。 |
| `-12004` | | 无效参数。 |
| `-12005` | | 无效 Revision 参数。 |
| `-12006` | | Metadata 长度溢出。 |
| `-12007` | | 无效 Lock 名称。 |
| `-12008` | | 未获取该 Lock。 |
| `-12009` | | 无效 Metadata 键。 |
| `-12010` | | 无效 Metadata 值。 |
| `-12011` | | Metadata 键长度溢出。 |
| `-12012` | | Metadata 值长度溢出。 |
| `-12013` | | 重复的 Metadata Item 键。 |
| `-12014` | | Metadata Item 中的 Revision 过时或 Key 不存在。 |
| `-12015` | | 未订阅该频道。 |
| `-12016` | | Metadata 实例不存在。请创建 Metadata 实例。 |
| `-12017` | | 订阅用户 Metadata 数量超出限制。 |
| `-12018` | | Storage 操作超时。 |
| `-12019` | | Storage 服务不可用。 |
| `-13001` | | 用户未连接到系统。 |
| `-13002` | | Presence 服务不可用。 |
| `-13003` | | 无效参数。 |
| `-13004` | | 加入频道前缓存的临时用户状态超出限制。详见 [API 调用限制](/zh-CN/realtime-media/rtm/reference/usage-limits-and-errors/api-limits)。 |
| `-13005` | | 临时用户状态键/值对数量超出限制。详见 [API 调用限制](/zh-CN/realtime-media/rtm/reference/usage-limits-and-errors/api-limits)。 |
| `-13006` | | 无效状态键。 |
| `-13007` | | 无效状态值。 |
| `-13008` | | 状态键长度溢出。 |
| `-13009` | | 状态值长度溢出 |
| `-13010` | | 重复的状态键。 |
| `-13011` | | 该用户不存在。 |
| `-13012` | `PRESENCE_OPERATION_TIMEOUT` | Presence 操作超时。 |
| `-13013` | `PRESENCE_OPERATION_FAILED` | Presence 操作失败。 |
| `-13014` | `PRESENCE_INACTIVE` | Presence 服务未开启或当前不可用。请检查声网控制台是否已开启 Presence 服务开关;未开启时,依赖该服务的 Presence API 和订阅选项不可用。 |
| `-13015` | `PRESENCE_PENDING_REQUEST_CANCELLED` | Presence 待处理请求已取消。调用 Presence 相关 API 后,如果请求完成前被取消,会返回该错误。 |
| `-13016` | `PRESENCE_PENDING_REQUEST_EXCEED_LIMITATION` | Presence 待处理请求数量超过限制。请等待已有请求完成后重试。 |
| `-14001` | | Lock 操作失败。 |
| `-14002` | | Lock 操作超时。 |
| `-14003` | | Lock 操作进行中。 |
| `-14004` | | Lock 已存在。 |
| `-14005` | | 无效 Lock 名。 |
| `-14006` | | 未获取该 Lock。 |
| `-14007` | | 获取该 Lock 失败。 |
| `-14008` | | 该 Lock 不存在。 |
| `-14009` | | Lock 服务不可用。 |
| `-15001` | | 历史消息的操作失败。 |
| `-15002` | | 历史消息的时间戳无效。 |
| `-15003` | | 历史消息的操作超时。 |
| `-15004` | | 没有权限进行历史消息的操作。 |
| `-15005` | | 历史消息服务不可用。 |
**error-codes-android-ios-swift-cpp-unity-harmonyos-html-0-4-2 details**
无效 App ID:
- 检查 App ID 是否错误。
- 检查 App ID 是否开通了 RTM 服务。
**error-codes-android-ios-swift-cpp-unity-harmonyos-html-0-6-2 details**
无效用户 ID:
- 检查用户 ID 是否为空。
- 检查用户 ID 是否包含非法字符。
**error-codes-android-ios-swift-cpp-unity-harmonyos-html-0-8-2 details**
无效频道名称:
- 检查频道名是否为空。
- 检查频道名是否包含非法字符。
**error-codes-android-ios-swift-cpp-unity-harmonyos-html-0-12-2 details**
SDK 被服务器拒绝登录:
- 检查 App ID 是否开通 RTM 服务。
- 检查 Token 或 `userId` 是否被封禁。
**error-codes-android-ios-swift-cpp-unity-harmonyos-html-0-13-2 details**
由于未知问题 SDK 登录中断:
- 检查当前网络是否稳定,切换到稳定网络环境中。
- 当前 `userId` 在其他端登录。
**error-codes-android-ios-swift-cpp-unity-harmonyos-html-0-19-2 details**
频道类型无效。SDK 仅支持如下频道类型,请填写正确的值:
- `MESSAGE`: Message Channel
- `STREAM`: Stream Channel
- `USER`: User Channel
**error-codes-android-ios-swift-cpp-unity-harmonyos-html-0-20-2 details**
消息加密参数无效。
- 检查生成的加密密钥是否为字符串类型。
- 检查生成的加密盐是否为字节数组类型,长度是否为 32 字节。
- 检查加密方式与加密密钥、加密盐是否匹配。
**error-codes-android-ios-swift-cpp-unity-harmonyos-html-0-23-2 details**
登录操作已取消。可能原因如下:
- 调用 `login` 方法后,如果你在收到调用结果之前再次调用该方法,则前一次的调用操作会被取消,SDK 会执行后一次的调用。
- 还未成功登录就调用 `logout` 方法登出。
**error-codes-android-ios-swift-cpp-unity-harmonyos-html-0-27-2 details**
用户未加入该频道:
- 用户不在线、已离线或未加入该频道
- 检查 `userId` 是否拼写错误。
**error-codes-android-ios-swift-cpp-unity-harmonyos-html-0-28-2 details**
用户未订阅该频道:
- 用户不在线、已离线或未加入该频道
- 检查 `userId` 是否拼写错误。
**error-codes-android-ios-swift-cpp-unity-harmonyos-html-0-33-2 details**
加入该频道失败:
- 检查已加入频道数量是否超限。
- 检查频道名是否非法。
- 检查网络是否断开连接。
**error-codes-android-ios-swift-cpp-unity-harmonyos-html-0-34-2 details**
无效 Topic 名:
- 检查 Topic 名是否包含非法字符。
- 检查 Topic 名是否为空。
**error-codes-android-ios-swift-cpp-unity-harmonyos-html-0-36-2 details**
消息长度超出限制。检查消息负载大小是否超限:
- Message Channel 单个消息包小于 32 KB。
- Stream Channel 单个消息包小于 1 KB。
**error-codes-android-ios-swift-cpp-unity-harmonyos-html-0-37-2 details**
无效用户列表:
- 检查用户列表是否为空
- 检查用户列表是否包含非法项。
**error-codes-android-ios-swift-cpp-unity-harmonyos-html-0-49-2 details**
消息加密失败:
- 检查加密密钥是否有效。
- 检查加密盐是否有效。
- 检查加密方式与加密密钥、加密盐是否匹配。
**error-codes-android-ios-swift-cpp-unity-harmonyos-html-0-58-2 details**
发送用户消息时,远端用户不在线:
- 检查在调用方法时设置的用户 ID 是否正确。
- 检查远端用户是否登录系统并处于在线状态。
## 联系我们 [#联系我们-3]
如果以上措施都为未能解决你的故障,或者你需要解决方案的支持,请将你的需求整理出来并通过邮箱发送到:rtm-support@agora.io。我们会在收到邮件的第一时间与你取得联系。