How to use the @unimodules/core.CodedError function in @unimodules/core

To help you get started, we’ve selected a few @unimodules/core examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github expo / expo / packages / expo-app-auth / build / AppAuth.js View on Github external
function parseRetryTime(value) {
    // In accordance with RFC2616, Section 14.37. Timout may be of format seconds or future date time value
    if (/^\d+$/.test(value)) {
        return parseInt(value, 10) * 1000;
    }
    const retry = Date.parse(value);
    if (isNaN(retry)) {
        throw new CodedError('ERR_APP_AUTH_FETCH_RETRY_TIME', 'Cannot parse the Retry-After header value returned by the server: ' + value);
    }
    const now = Date.now();
    const parsedDate = new Date(retry);
    return parsedDate.getTime() - now;
}
export const { OAuthRedirect, URLSchemes } = ExpoAppAuth;
github expo / expo / packages / expo-font / src / Font.ts View on Github external
async function loadFontInNamespaceAsync(
  fontFamily: string,
  source?: FontSource | null
): Promise {
  if (!source) {
    throw new CodedError(
      `ERR_FONT_SOURCE`,
      `Cannot load null or undefined font source: { "${fontFamily}": ${source} }. Expected asset of type \`FontSource\` for fontFamily of name: "${fontFamily}"`
    );
  }

  if (loaded[fontFamily]) {
    return;
  }

  if (loadPromises[fontFamily]) {
    return loadPromises[fontFamily];
  }

  // Important: we want all callers that concurrently try to load the same font to await the same
  // promise. If we're here, we haven't created the promise yet. To ensure we create only one
  // promise in the program, we need to create the promise synchronously without yielding the event
github expo / expo / packages / expo-app-auth / build / AppAuth.js View on Github external
}
    const encodedClientID = encodeURIComponent(clientId);
    const encodedToken = encodeURIComponent(token);
    const body = `token=${encodedToken}${isClientIdProvided ? `&client_id=${encodedClientID}` : ''}`;
    const headers = { 'Content-Type': 'application/x-www-form-urlencoded' };
    try {
        // https://tools.ietf.org/html/rfc7009#section-2.2
        const results = await fetch(revocationEndpoint, {
            method: 'POST',
            headers,
            body,
        });
        return results;
    }
    catch (error) {
        throw new CodedError('ERR_APP_AUTH_REVOKE_FAILED', error.message);
    }
}
// NOTE: This function is unused; delete it if we don't need it
github expo / expo / packages / expo-font / build / Font.js View on Github external
async function unloadFontInNamespaceAsync(fontFamily, options) {
    if (!loaded[fontFamily]) {
        return;
    }
    else {
        delete loaded[fontFamily];
    }
    // Important: we want all callers that concurrently try to load the same font to await the same
    // promise. If we're here, we haven't created the promise yet. To ensure we create only one
    // promise in the program, we need to create the promise synchronously without yielding the event
    // loop from this point.
    const nativeFontName = getNativeFontName(fontFamily);
    if (!nativeFontName) {
        throw new CodedError(`ERR_FONT_FAMILY`, `Cannot unload an empty name`);
    }
    await ExpoFontLoader.unloadAsync(nativeFontName, options);
}
export { FontDisplay };
github expo / expo / packages / expo-google-app-auth / src / Google.ts View on Github external
function guidFromClientId(clientId: string): string {
  const clientIdComponents = clientId.split('.').filter(component => component.includes('-'));

  const guid = clientIdComponents[0];
  const { isValid, reason } = isValidGUID(guid);
  if (!isValid) {
    throw new CodedError(
      'ERR_GOOGLE_GUID',
      reason + ' Please ensure you copied the client ID correctly.'
    );
  }

  return guid;
}
github expo / expo / packages / expo-app-auth / build / AppAuth.js View on Github external
function assertValidProps({ issuer, redirectUrl, clientId, serviceConfiguration, }) {
    if (typeof issuer !== 'string' && !isValidServiceConfiguration(serviceConfiguration)) {
        throw new CodedError('ERR_APP_AUTH_INVALID_CONFIG', 'You must provide either an `issuer` or both `authorizationEndpoint` and `tokenEndpoint`');
    }
    if (typeof redirectUrl !== 'string') {
        throw new CodedError('ERR_APP_AUTH_INVALID_CONFIG', '`redirectUrl` must be a string');
    }
    assertValidClientId(clientId);
}
async function _executeAsync(props) {
github expo / expo / packages / expo-font / build / Font.js View on Github external
export async function unloadAllAsync() {
    if (!ExpoFontLoader.unloadAllAsync) {
        throw new UnavailabilityError('expo-font', 'unloadAllAsync');
    }
    if (Object.keys(loadPromises).length) {
        throw new CodedError(`ERR_UNLOAD`, `Cannot unload fonts while they're still loading: ${Object.keys(loadPromises).join(', ')}`);
    }
    for (const fontFamily of Object.keys(loaded)) {
        delete loaded[fontFamily];
    }
    await ExpoFontLoader.unloadAllAsync();
}
/**
github expo / expo / packages / expo-app-auth / src / AppAuth.ts View on Github external
function assertValidProps({
  issuer,
  redirectUrl,
  clientId,
  serviceConfiguration,
}: OAuthProps): void {
  if (typeof issuer !== 'string' && !isValidServiceConfiguration(serviceConfiguration)) {
    throw new CodedError(
      'ERR_APP_AUTH_INVALID_CONFIG',
      'You must provide either an `issuer` or both `authorizationEndpoint` and `tokenEndpoint`'
    );
  }
  if (typeof redirectUrl !== 'string') {
    throw new CodedError('ERR_APP_AUTH_INVALID_CONFIG', '`redirectUrl` must be a string');
  }
  assertValidClientId(clientId);
}
github expo / expo / packages / expo / build / Notifications / Notifications.js View on Github external
async scheduleNotificationWithCalendarAsync(notification, options = {}) {
        const areOptionsValid = (options.month == null || isInRangeInclusive(options.month, 1, 12)) &&
            (options.day == null || isInRangeInclusive(options.day, 1, 31)) &&
            (options.hour == null || isInRangeInclusive(options.hour, 0, 23)) &&
            (options.minute == null || isInRangeInclusive(options.minute, 0, 59)) &&
            (options.second == null || isInRangeInclusive(options.second, 0, 59)) &&
            (options.weekDay == null || isInRangeInclusive(options.weekDay, 1, 7)) &&
            (options.weekDay == null || options.day == null);
        if (!areOptionsValid) {
            throw new CodedError('WRONG_OPTIONS', 'Options in scheduleNotificationWithCalendarAsync call were incorrect!');
        }
        _validateNotification(notification);
        let nativeNotification = _processNotification(notification);
        return ExponentNotifications.scheduleNotificationWithCalendar(nativeNotification, options);
    },
    async scheduleNotificationWithTimerAsync(notification, options) {