Skip to content

isNativeError

Narrows a bridge error to a native error. Native errors are returned by the host application after it receives and handles the request.

Importing

ts
import { isNativeError } from '@almighty-shogun/webkit-native-bridge';

Usage

ts
import {
    createNativeBridge,
    isNativeError
} from '@almighty-shogun/webkit-native-bridge';

type Requests = {
    getUser: {
        body: {
            id: string;
        };
        response: {
            name: string;
        }
    }
};

const bridge = createNativeBridge<Requests>();
const response = await bridge.request('getUser', { id: '1' });

if (!response.ok && isNativeError(response.error)) {
    console.warn('Native code rejected the request');
}

Parameters

error: BridgeError<TCode, TDetails>
Error to inspect.

Returns

true when the error was returned by native code. TypeScript narrows error.type to native in the true branch.

Type signature

ts
declare function isNativeError<TCode extends string, TDetails>(
    error: BridgeError<TCode, TDetails>
): error is BridgeError<TCode, TDetails> & { type: 'native' };

All packages are released under the MIT License.