Error codes
Rejected promises carry a code; onError events carry { code, message }.
try { await LongPing.start();} catch (e: any) { switch (e.code) { case 'PERMISSION_DENIED': return showPermissionScreen(); case 'LOCATION_SERVICES_OFF': return LongPing.deviceSettings.openLocationSettings(); default: throw e; }}| Code | Raised by | Means | What to do |
|---|---|---|---|
INVALID_CONFIG |
configure(), setConfig(), getLog() options |
A value has the wrong type, http.url isn’t an absolute http(s) URL, lowBattery lacks a field, minAccuracyM is negative, or locationTemplate has an unknown token or doesn’t render valid JSON. The message names the key. |
Fix the value. Out-of-range numbers are clamped, not rejected. |
PERMISSION_DENIED |
start(); error event at launch |
Location permission is missing. | Show your rationale, then requestPermission(), or send the user to Settings. |
LOCATION_SERVICES_OFF |
start() |
Location services are switched off on the device. | deviceSettings.openLocationSettings(). |
NOT_ENABLED |
changePace() |
Tracking is stopped. | Call start() first. |
TIMEOUT |
getCurrentPosition() |
No fix in timeoutSec and no last known fix younger than 10 minutes. |
Retry, raise timeoutSec, or check signal and permission. |
NO_ACTIVITY |
requestPermission() (Android) |
There was no foreground Activity to show the dialog. | Call it while your app is in the foreground. |
INTERNAL |
Any | Something unexpected failed natively. | Check logger.getLog(); report it with the log. |
The same codes are exported as a TypeScript type:
import type { ErrorCode } from 'react-native-long-ping';