Function isSdkError

  • Type guard to check if an error is an SDK error

    This function checks if an error object has the structure of an SDK error by verifying it has the required properties: message, code, and status.

    Parameters

    • err: any

      Any error object to check

    Returns err is ErrorResponse

    True if the error is an SDK error, false otherwise

    try {
    const users = await mosaia.users.get();
    } catch (error) {
    if (isSdkError(error)) {
    console.log('SDK Error:', error.message);
    console.log('Error Code:', error.code);
    console.log('Status:', error.status);
    } else {
    console.log('Unexpected error:', error);
    }
    }