Troubleshooting Sanad

What the SDK's diagnostics codes mean, and how to fix common integration problems.

Every Sanad SDK has a diagnostics() call that returns the SDK's state, its sessionId, the lastError and the sdkVersion. It holds codes only, never device data or credentials, so it's safe to log and to attach to a support ticket. Include sdkVersion whenever you contact Lean.

The codes are the same on Android, iOS and web. Android writes the states in capitals (ACTIVE), and iOS and web in lower case (active).

SDK states

StateMeaning
IDLENo session: init hasn't been called yet, or it failed in a way you can retry
OPENINGinit is opening the session
ACTIVEA session is open, and collect() works
STOPPEDLean refused the key or the app. It lasts until the app restarts or the page reloads
RESETTINGReserved for a future release

SDK errors

lastErrorWhat happenedWhat to do
invalid_sdk_keyLean doesn't know the SDK keyCheck the key, and that it matches the build's environment, sandbox or production
forbiddenLean refused the app or this deviceCheck that Sanad is enabled for your application. During development, clearing the app's or the site's data helps after switching between applications or environments
networkLean couldn't be reachedCheck the connection, and that no proxy, firewall or Content Security Policy blocks Lean's host. You can call init again
rate_limitedLean asked the SDK to slow downNothing: the SDK backs off on its own
server_errorA temporary problem on Lean's sideNothing: the SDK retries on its own
bad_response, malformed, too_largeA request or response was invalidContact Lean with the sdkVersion
key_unavailableThe device couldn't create the SDK's key (Android Keystore, iOS Secure Enclave, or the browser's key store)Rare; there's no session on that device. On iOS, make sure the app is signed
frame_unavailableWeb only: Lean's frame didn't load within 10 secondsCheck that your Content Security Policy allows sanad.leantech.me in script-src and frame-src, and that the page can reach it. You can call init again
already_initialisedinit was called again with a different keyUse one key per app build
session_not_foundLean has no such session for this appMake sure the key and environment didn't change while the app was running
envelope_capThe session already sent 10 sets of signalsExpected if you call collect() very often. Call it before sensitive actions only
internalAn unexpected error inside the SDKContact Lean with the sdkVersion

Treat a lastError you don't recognise as opaque: log it, and carry on without Sanad.

Backend problems

SymptomCauseWhat to do
400 invalid_request from /oauth2/tokenWrong client_id or client_secretCheck your credentials in the Application Dashboard
401 or 403 from the assessmentThe token is missing or expired, or wasn't requested with scope=apiGet a new token with scope=api
404 Session not foundThe session belongs to another application or environmentMake sure the SDK key and the client credentials belong to the same application, and are both sandbox or both production
NO_OBSERVATIONS for more than about 15 secondsThe app opened a session, but no signals reached LeanCheck diagnostics() in your app, and that collectOnInit is on or collect() is called
The same assessment_id after collect()The new signals are still being assessedAsk again every 2 seconds. See Reading assessments
emulator_detected on your test deviceYou're testing on an emulator or simulatorTest on a real device
INSUFFICIENT_DATA in location_analysisYour app has no location permission, or your user declined itNothing: this is expected, and isn't a risk signal by itself

Did this page help you?