@wwdrew/expo-spotify-sdk
Version:
Expo module wrapping the native Spotify iOS (v5) and Android (v4) SDKs for OAuth authentication and App Remote playback control
26 lines • 1.19 kB
JavaScript
const CAUSE_SEPARATOR = "→ Caused by: ";
function unwrapReason(message) {
const idx = message.lastIndexOf(CAUSE_SEPARATOR);
return idx === -1 ? message : message.slice(idx + CAUSE_SEPARATOR.length);
}
export function createNativeErrorRethrow(options) {
const { ErrorClass, validCodes, unknownCode } = options;
return function rethrowNativeError(err) {
if (err instanceof ErrorClass)
throw err;
if (err instanceof Error) {
const reason = unwrapReason(err.message);
// `err.code` is the structured code from the native `Exception`. On iOS
// before Expo SDK 57 the async-rejection bridge dropped it (the message
// survived), surfacing as `unknownCode` with the correct message; fixed
// in Expo SDK 57 (expo/expo#47259), which preserves the code.
const maybeCode = err.code;
if (maybeCode && validCodes.has(maybeCode)) {
throw new ErrorClass(maybeCode, reason);
}
throw new ErrorClass(unknownCode, reason);
}
throw new ErrorClass(unknownCode, String(err));
};
}
//# sourceMappingURL=native-errors.js.map