UNPKG

@wscsports/blaze-rtn-sdk

Version:
70 lines (65 loc) 2.28 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.BlazeException = void 0; exports.mapToBlazeErrorOrRethrow = mapToBlazeErrorOrRethrow; exports.parseBlazeError = parseBlazeError; exports.tryParseBlazeErrorFromPromiseRejection = tryParseBlazeErrorFromPromiseRejection; 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 exports.BlazeException = BlazeException; 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) 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 function mapToBlazeErrorOrRethrow(error) { const blazeError = tryParseBlazeErrorFromPromiseRejection(error); if (blazeError) { const exception = new BlazeException(blazeError); throw exception; } throw error; } //# sourceMappingURL=blaze-error.interface.js.map