> ## Documentation Index
> Fetch the complete documentation index at: https://learn.social.plus/llms.txt
> Use this file to discover all available pages before exploring further.

# Logging & Errors

> Monitor SDK network activity during integration and handle SDK error codes safely.

Use SDK logging and error surfaces while you build and debug an integration. Keep request and response logging out of production logs unless your app has an explicit redaction and retention policy.

## SDK Surface

| Need                      | TypeScript                                         | iOS                                   | Android                                      | Flutter                              |
| ------------------------- | -------------------------------------------------- | ------------------------------------- | -------------------------------------------- | ------------------------------------ |
| Network activity observer | `Client.onNetworkActivities(callback)`             | `client.observeNetworkActivities(_:)` | `AmityCoreClient.observeNetworkActivities()` | Not exposed as a public SDK observer |
| Error parsing             | `error.code` from SDK errors and connection events | `AmityErrorCode(rawValue:)`           | `AmityError.from(...)`                       | `AmityException.toAmityError()`      |
| Global ban signal         | `Amity.ServerError.GLOBAL_BAN`                     | `.globalBan`                          | `AmityError.USER_IS_GLOBAL_BANNED`           | `AmityError.USER_IS_GLOBAL_BANNED`   |

<Info>
  Use the network observer as a development diagnostic tool. It can expose request metadata, response metadata, and payloads depending on platform, so avoid storing raw logs that may contain user content or credentials.
</Info>

## Parameters

| Platform   | Callback or stream value                   | Notes                                                                                                                            |
| ---------- | ------------------------------------------ | -------------------------------------------------------------------------------------------------------------------------------- |
| TypeScript | `request`, `response`                      | `response` includes `data`, `status`, `statusText`, and `headers`. The API returns an unsubscriber.                              |
| iOS        | `URLRequest?`, `HTTPURLResponse?`, `Data?` | Pass `nil` to `observeNetworkActivities` when logging should stop.                                                               |
| Android    | `Flowable<AmityNetworkActivity>`           | Subscribe while debugging and dispose the subscription when finished. Avoid depending on internal activity subtypes in app code. |
| Flutter    | Not available                              | Use normal request-level error handling and your app's HTTP tooling for Flutter-specific network diagnostics.                    |

## Network Activity

Observe network activity only while debugging an integration, then unsubscribe or dispose the observer when the debug session ends.

<CodeGroup>
  ```typescript TypeScript theme={null}
  import { Client } from '@amityco/ts-sdk';

  const unsubscribe = Client.onNetworkActivities((request, response) => {
    console.log(request.method, request.url);
    console.log(response.status, response.statusText);
    console.log(response.data);
  });

  // Stop observing when the debug session ends.
  unsubscribe();
  ```

  ```swift iOS theme={null}
  client.observeNetworkActivities { request, response, data in
      if let request {
          print("\(request.httpMethod ?? "GET") \(request.url?.absoluteString ?? "")")
      }

      if let response {
          print("status: \(response.statusCode)")
      }

      if let data {
          print("response bytes: \(data.count)")
      }
  }

  // Stop observing when the debug session ends.
  client.observeNetworkActivities(nil)
  ```

  ```kotlin Android theme={null}
  val disposable = AmityCoreClient.observeNetworkActivities()
      .doOnNext { activity ->
          print(activity)
      }
      .doOnError { exception ->
          val amityError = AmityError.from(exception)
          print(amityError)
      }
      .subscribe()

  // Stop observing when the debug session ends.
  disposable.dispose()
  ```
</CodeGroup>

## Error Handling

SDK operations throw or emit platform-native errors. Convert those errors to SDK error enums before deciding whether to retry, show a user message, or end the session.

<CodeGroup>
  ```typescript TypeScript theme={null}
  import { Client } from '@amityco/ts-sdk';

  const unsubscribe = Client.onConnectionError(error => {
    if (error.code === Amity.ServerError.GLOBAL_BAN) {
      console.log('The current user is globally banned.');
    }
  });

  unsubscribe();
  ```

  ```swift iOS theme={null}
  func handleSdkError(_ error: Error) {
      let sdkError = error as NSError

      guard let amityError = AmityErrorCode(rawValue: sdkError.code) else {
          showErrorMessage("Unknown SDK error", error: error)
          return
      }

      if amityError == .globalBan {
          showErrorMessage("The current user is globally banned", error: error)
      }
  }
  ```

  ```kotlin Android theme={null}
  fun handleSdkError(exception: Throwable) {
      val amityError = AmityError.from(exception)

      if (amityError == AmityError.USER_IS_GLOBAL_BANNED) {
          print("The current user is globally banned.")
      }
  }
  ```

  ```dart Flutter theme={null}
  final Object error = AmityException(
    message: 'The current user is globally banned.',
    code: 400312,
  );

  if (error is AmityException) {
    final amityError = error.toAmityError();

    if (amityError == AmityError.USER_IS_GLOBAL_BANNED) {
      showError(error);
    }
  }
  ```
</CodeGroup>

## Common SDK Error Constants

| Meaning                      | TypeScript                                               | iOS                          | Android                                   | Flutter                                                        |
| ---------------------------- | -------------------------------------------------------- | ---------------------------- | ----------------------------------------- | -------------------------------------------------------------- |
| Globally banned user         | `Amity.ServerError.GLOBAL_BAN`                           | `.globalBan`                 | `AmityError.USER_IS_GLOBAL_BANNED`        | `AmityError.USER_IS_GLOBAL_BANNED`                             |
| Unauthorized session         | `Amity.ServerError.UNAUTHORIZED`                         | `.unauthorized`              | `AmityError.UNAUTHORIZED_ERROR`           | `AmityError.UNAUTHORIZED_ERROR`                                |
| Item not found               | `Amity.ServerError.ITEM_NOT_FOUND`                       | `.itemNotFound`              | `AmityError.ITEM_NOT_FOUND`               | `AmityError.ITEM_NOT_FOUND`                                    |
| Permission denied            | `Amity.ServerError.PERMISSION_DENIED`                    | `.permissionDenied`          | `AmityError.PERMISSION_DENIED`            | `AmityError.PERMISSION_DENIED`                                 |
| Visitor usage limit exceeded | `Amity.ServerError.VISITOR_USAGE_LIMIT_EXCEEDED`         | `.visitorUsageLimitExceeded` | `AmityError.VISITOR_USAGE_LIMIT_EXCEEDED` | Not exposed as a public Flutter SDK enum in the current source |
| Visitor permission denied    | `Amity.ServerError.VISITOR_PERMISSION_DENIED`            | `.visitorPermissionDenied`   | `AmityError.VISITOR_PERMISSION_DENIED`    | Not exposed as a public Flutter SDK enum in the current source |
| Bot permission denied        | `Amity.ServerError.BOT_PERMISSION_DENIED`                | `.botPermissionDenied`       | `AmityError.BOT_PERMISSION_DENIED`        | Not exposed as a public Flutter SDK enum in the current source |
| Max blocked users reached    | `Amity.ServerError.MAX_BLOCKED_USERS_REACHED` (`400324`) | `.maxBlockedUsersReached`    | `AmityError.MAX_BLOCKED_USERS_REACHED`    | Refer to platform SDK                                          |
| Connection error             | `Amity.ClientError.CONNECTION_ERROR`                     | `.connectionError`           | `AmityError.CONNECTION_ERROR`             | `AmityError.CONNECTION_ERROR`                                  |

## Production Checklist

* Disable broad network payload logging outside development builds.
* Redact tokens, authorization headers, user identifiers, and message or post bodies before writing logs.
* Keep retry logic bounded and avoid retrying authorization or global-ban errors.
* Show user-friendly messages in the app UI; keep SDK codes in developer logs and support diagnostics.
* Unsubscribe or dispose observers when the screen, debug session, or application lifecycle no longer needs them.
