Error Handling
Code | Error Name | Description |
400000 | BadRequestError | Request contains invalid parameters. |
400001 | InvalidRegularExpression | An invalid regex rule retrieved from or added to the Blocklist |
400002 | VideoFormatInvalidRequestError | Video format not supported |
400100 | UnauthorizedError | Unverified user performs any action that requires access token verification. |
400300 | ForbiddenError | User performs forbidden action such as uploading a pdf file in an image message. |
400301 | PermissionDenied | User has no permission to perform the action. |
400302 | UserIsMuted | A muted user sends a message. |
400303 | ChannelIsMuted | User sends a message in a muted channel. |
400304 | UserIsBanned | User accessed a channel or community where he is banned. |
400307 | MaxRepetitionExceed | User reached the limit of the number of sent messages containing blocklisted words. |
400308 | BanWordFound | User sends a message that contains a blocklisted word. |
400309 | LinkNotAllowed | User sends a message that contains link that is not in the Allowlist. |
400311 | RPCRateLimitError | Web socket rate limit is exceeded. |
400312 | GlobalBanError | Banned user performs any action. |
400314 | UnsafeContent | Content moderation system detects unsafe content (eg. nudity). |
400315 | DuplicateEntryError | Display name of a collection already exists (eg. for your channels or community categories). |
400316 | UserIsUnbanned | Returned when unbanning a user that is not banned. |
400317 | ForbiddenError | The only active moderator in a channel/community attempts to leave and there are no other moderators in the group. |
400318 | ForbiddenError | The only moderator in a channel/community attempts to leave and there are no other members in the group. |
400319 | ForbiddenError | User changes module and user notification settings but the network notification setting is off. |
400400 | ItemNotFound | System cannot find any resource matched with the requested condition. |
400900 | Conflict | System cannot create/update duplicated data. |
500000 | BusinessError | Uncategorized internal system errors not related to any user input. |
500000 | BusinessError | Video upload failed |
Code | Error Name | Description |
800000 | Unknown | Uncategorized errors. To debug, refer to the 'error.message' property. |
800110 | InvalidParameter | Data type of the parameter is invalid. |
800210 | ConnectionError | Websocket connection of the SDK cannot reach the platform server. This could also be the case if a user is global-banned and try to register a session. |
Error objects can be returned to you via LiveObjects, callbacks, or client error delegates. The possible error codes are listed in a public error code enum: each case is named after its error.
You can convert an Amity Exception into an Amity Error with the following:
iOS
Android
JavaScript
TypeScript
func parseError(_ error: Error) {
let sdkError = error as NSError
guard let amityError = AmityErrorCode(rawValue: sdkError.code) else {
// Unknown error occurred. Please report this error code to Amity
return
}
// ...
// Process AmityError here..
}
All the errors returned by the iOS SDK come in form of an
NSError
with domain Amity
.For asynchronous errors, the client includes a
clientErrorDelegate
property that can be set to an error handler delegate class on your application. This error delegate gives you a chance to be notified of errors that can potentially break the functionality of the SDK. The SDK logic is usually robust enough to automatically handle most errors, as such, only unrecoverable errors are exposed through this delegate (for example, if the login session was invalidated).We recommend you to always handle these errors in a production app by gracefully disabling messaging functionality in the event of an error.
var client: AmityClient?
client.clientErrorDelegate = self // set yourself as the delegate
...
// Implement this delegate method which gets called when error occurs
func didReceiveAsyncError(_ error: Error) {
// Handle error here
}
AmityError enums map to the supported error scenarios
import { ErrorCode, CommunityRepository } from '@amityco/js-sdk'
const liveObject = CommunityRepository.communityForId('abc');
liveObject.on("dataUpdated", data => {
// community is fetched
});
liveObject.on("dataError", err => {
// failed to fetch the community
console.log(err.code == ErrorCode.BusinessError);
}
All the errors returned by the SDK come in form of an Error with domain
ASC
. When an error is returned as a result of an action from your side (e.g. trying to join a channel), the action is considered completed and the SDK will not execute any additional logic.
A global ban error means that the user is banned from the system resulting in the inability to have a connection with the system. If the user already has a session, the session will be revoked and will be unable to create a new session.
iOS
Android
JavaScript
TypeScript
var client: AmityClient?
client.clientErrorDelegate = self // set yourself as the delegate
...
// Implement this delegate method which gets called when error occurs
func didReceiveAsyncError(_ error: Error) {
let error = error as NSError
guard let amityError = AmityErrorCode(rawValue: error.code) else {
assertionFailure("unknown error \(error.code), please report this code to Amity")
return
}
if amityError == .globalBan {
// Handle global ban event here
}
}
Banned while not having a session
Observing the LiveObject for ban while having a session
client = new ASCClient({ apiKey, apiEndpoint });
client.on('dataError', error => {
if (error.code === ErrorCode.GlobalBanError) {
// handle the case the user is globally banned
}
});
Last modified 1mo ago