Response codes

Sparkling Method response codes follow the Android/iOS native bridge convention. This convention is the source of truth for sparkling-method, generated method wrappers, and built-in method packages.

CodeMeaning
1Success
0Method executed but failed
NegativeBridge, parameter, permission, timeout, or infrastructure error

Common negative codes

CodeMeaning
-1JS-side validation or local wrapper error
-2Method not registered / no handler
-3Invalid parameters
-5Invalid result
-6Unauthorized access
-7Operation cancelled
-8Operation timeout
-9Not found
-997Frontend returned 404
-998Frontend method undefined
-999Manual callback from business side
-1000Unknown error
-1001Network unreachable
-1002Network timeout
-1003Malformed response

Usage

methodCall(params, (res) => {
  if (res.code === 1) {
    // success
    return;
  }

  console.error(res.msg);
});

Use res.code === 1 for success checks and res.code !== 1 for failure checks. Do not treat 0 as success.