UNPKG

@wscsports/blaze-rtn-sdk

Version:
60 lines (56 loc) 1.96 kB
export class BlazeException extends Error { constructor(blazeError) { super(blazeError.message || 'Blaze SDK Error'); this.name = 'BlazeException'; this.blazeError = blazeError; } toString() { return `BlazeException - For access to more details please cast it into \`BlazeException\`: ${JSON.stringify(this.blazeError)})`; } } // Helper function to parse BlazeError from a JSON string export function tryParseBlazeErrorFromPromiseRejection(error) { try { // Check if this is a Blaze convertible error if (error && typeof error === 'object' && error.code === 'BLAZE_CONVERTIBLE_ERROR') { let detailsString = null; // React Native NSError structure: details are in userInfo.details if (error.userInfo && typeof error.userInfo === 'object' && typeof error.userInfo.details === 'string') { detailsString = error.userInfo.details; } // Fallback: check if details is directly on the error object else if (typeof error.details === 'string') { detailsString = error.details; } if (detailsString) { return parseBlazeError(detailsString) || null; } } } catch (e) { return null; } return null; } // Helper function to parse BlazeError from a JSON string (for event data) export function parseBlazeError(errorString) { if (!errorString || typeof errorString !== 'string') { return undefined; } try { const jsonMap = JSON.parse(errorString); return jsonMap; } catch (e) { console.error('Failed to parse BlazeError from string:', errorString, e); return undefined; } } // Helper function to map error to BlazeException or rethrow export function mapToBlazeErrorOrRethrow(error) { const blazeError = tryParseBlazeErrorFromPromiseRejection(error); if (blazeError) { const exception = new BlazeException(blazeError); throw exception; } throw error; } //# sourceMappingURL=blaze-error.interface.js.map