Skip to content

Commit

Permalink
fix: throw if requesting an unsupported provider instance
Browse files Browse the repository at this point in the history
  • Loading branch information
mfkrause committed Apr 25, 2024
1 parent 435a46f commit dbbb5c3
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions src/RNCloudStorage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import createNativeCloudStorage from './createRNCloudStorage';
import { CloudStorageProvider, CloudStorageScope, type CloudStorageFileStat } from './types/main';
import { providerService } from './ProviderService';
import type NativeRNCloudStorage from './types/native';
import { isProviderSupported } from './utils/helpers';

const createCloudStorage = (nativeInstance: NativeRNCloudStorage) => ({
/**
Expand Down Expand Up @@ -168,13 +169,21 @@ let RNCloudStorage = {
* Gets a new instance of the CloudStorage API for the given provider.
* @param provider The provider to get an instance for.
* @returns A new instance of the CloudStorage API, without the provider configuration methods.
* @throws An error if the provider is not supported on the current platform.
*/
getProviderInstance: (provider: CloudStorageProvider) => createCloudStorage(createNativeCloudStorage(provider)),
getProviderInstance: (provider: CloudStorageProvider) => {
if (!isProviderSupported(provider)) {
throw new Error(`Provider ${provider} is not supported on the current platform.`);
}

return createCloudStorage(createNativeCloudStorage(provider));
},

/**
* Gets the list of supported CloudStorageProviders on the current platform.
* @returns An array of supported CloudStorageProviders.
*/ getSupportedProviders: providerService.getSupportedProviders,
*/
getSupportedProviders: providerService.getSupportedProviders,

/**
* Gets the current CloudStorageProvider.
Expand Down

0 comments on commit dbbb5c3

Please sign in to comment.