Transifex

  • Documentation
  • Javascript SDK
  • Error Handling

Error Handling

Note

Transifex Native is currently in BETA. To learn more about the solution or to have a hands on experience please get in touch with us.

The Transifex Native SDK solution protects the application from errors caused during rendering. All options are safeguarding an uninterrupted experience, securing your application from errors introduced by globalization process or unspecified rendering errors, like:

  • Missing variables (variables that exist in the translation but their value is not provided)
  • Malformed ICU messages (those would break the rendering of the ICU message)

Error handling is always applied, by checking the string to be rendered. If an error is found and the rendering of that translation string fails, an error policy is invoked, which defines what to render instead.

Source String

This is the default policy, where the source string will appear when an error occurs.

import { tx, SourceErrorPolicy } from '@transifex/native';

tx.init({
  errorPolicy: new SourceErrorPolicy(),
});

Throw Error

The throw error policy will not handle the error but throw it instead.

import { tx, ThrowErrorPolicy } from '@transifex/native';

tx.init({
  errorPolicy: new ThrowErrorPolicy(),
});

Custom Policy

You can implement custom error policies by creating a policy class based on the example below.

import { tx } from '@transifex/native';

class CustomErrorPolicy {
  handle(error, sourceString, localeCode, params) {
    return '<Error>';
  }  
}

tx.init({
  errorPolicy: new CustomErrorPolicy();
});