diff --git a/packages/@magic-sdk/provider/src/core/view-controller.ts b/packages/@magic-sdk/provider/src/core/view-controller.ts index e0da4c2a3..6e575c577 100644 --- a/packages/@magic-sdk/provider/src/core/view-controller.ts +++ b/packages/@magic-sdk/provider/src/core/view-controller.ts @@ -4,14 +4,13 @@ import { JsonRpcRequestPayload, MagicMessageEvent, MagicMessageRequest, - RPCErrorCode, - JsonRpcError, } from '@magic-sdk/types'; import { JsonRpcResponse } from './json-rpc'; import { createPromise } from '../util/promise-tools'; import { getItem, setItem } from '../util/storage'; import { createJwt } from '../util/web-crypto'; import { SDKEnvironment } from './sdk-environment'; +import { createModalNotReadyError } from './sdk-exceptions'; interface RemoveEventListenerFunction { (): void; @@ -140,10 +139,7 @@ export abstract class ViewController { // if the app was initially opened without internet connection. That is // why we reject the promise without waiting and just let them call it // again when internet connection is re-established. - const error: JsonRpcError = { - code: RPCErrorCode.InternalError, - message: 'Connection to Magic SDK not ready. Please check your internet connection.', - }; + const error = createModalNotReadyError(); reject(error); } diff --git a/packages/@magic-sdk/provider/test/spec/core/view-controller/post.spec.ts b/packages/@magic-sdk/provider/test/spec/core/view-controller/post.spec.ts index 3431c4324..f4c8b14fa 100644 --- a/packages/@magic-sdk/provider/test/spec/core/view-controller/post.spec.ts +++ b/packages/@magic-sdk/provider/test/spec/core/view-controller/post.spec.ts @@ -2,18 +2,13 @@ /* eslint-disable prefer-spread */ import browserEnv from '@ikscodes/browser-env'; -import { - MagicIncomingWindowMessage, - MagicOutgoingWindowMessage, - JsonRpcRequestPayload, - RPCErrorCode, -} from '@magic-sdk/types'; -import _ from 'lodash'; +import { MagicIncomingWindowMessage, MagicOutgoingWindowMessage, JsonRpcRequestPayload } from '@magic-sdk/types'; import { createViewController } from '../../../factories'; import { JsonRpcResponse } from '../../../../src/core/json-rpc'; import * as storage from '../../../../src/util/storage'; import * as webCryptoUtils from '../../../../src/util/web-crypto'; import { SDKEnvironment } from '../../../../src/core/sdk-environment'; +import { createModalNotReadyError } from '../../../../src/core/sdk-exceptions'; /** * Create a dummy request payload. @@ -220,10 +215,7 @@ test('does not wait for ready and throws error when platform is react-native', a try { await viewController.post(MagicOutgoingWindowMessage.MAGIC_HANDLE_REQUEST, payload); } catch (e) { - expect(e).toEqual({ - code: RPCErrorCode.InternalError, - message: 'Connection to Magic SDK not ready. Please check your internet connection.', - }); + expect(e).toEqual(createModalNotReadyError); } expect(createJwtStub).not.toHaveBeenCalledWith(); expect(onSpy.mock.calls[0][0]).toEqual(MagicIncomingWindowMessage.MAGIC_HANDLE_RESPONSE); diff --git a/packages/@magic-sdk/react-native-bare/README.md b/packages/@magic-sdk/react-native-bare/README.md index b69716222..98b9f7d1c 100644 --- a/packages/@magic-sdk/react-native-bare/README.md +++ b/packages/@magic-sdk/react-native-bare/README.md @@ -86,15 +86,16 @@ When attempting to import `Magic`, take note that the React Native metro bundler For this issue consider using Microsoft's [rnx-kit](https://microsoft.github.io/rnx-kit/docs/guides/bundling) suite of tools that include a plugin for metro that fixes this symlink related error. ### Handling internet connection problems -When an app is opened without internet connection, any request to the Magic SDK will result in a rejection with the following error: +When an app is opened without internet connection, any request to the Magic SDK will result in a rejection with a `MagicSDKError`: ```json { - "code": -32603, - "message": "Connection to Magic SDK not ready. Please check your internet connection." + "code": "MODAL_NOT_READY", + "rawMessage": "Modal is not ready." } ``` + It is good practice to use [@react-native-community/netinfo](https://www.npmjs.com/package/@react-native-community/netinfo) to track the internet connection state of the device. For your convenience, we've also added a hook that uses this library behind the scenes: diff --git a/packages/@magic-sdk/react-native-expo/README.md b/packages/@magic-sdk/react-native-expo/README.md index d681e8e0a..9f9aa6018 100644 --- a/packages/@magic-sdk/react-native-expo/README.md +++ b/packages/@magic-sdk/react-native-expo/README.md @@ -77,12 +77,12 @@ When attempting to import `Magic`, take note that the React Native metro bundler For this issue consider using Microsoft's [rnx-kit](https://microsoft.github.io/rnx-kit/docs/guides/bundling) suite of tools that include a plugin for metro that fixes this symlink related error. ### Handling internet connection problems -When an app is opened without internet connection, any request to the Magic SDK will result in a rejection with the following error: +When an app is opened without internet connection, any request to the Magic SDK will result in a rejection with a `MagicSDKError`: ```json { - "code": -32603, - "message": "Connection to Magic SDK not ready. Please check your internet connection." + "code": "MODAL_NOT_READY", + "rawMessage": "Modal is not ready." } ```