Skip to content

Commit

Permalink
feat: ensure LocalStorageAdapter throws StorageClearError when AsyncS…
Browse files Browse the repository at this point in the history
…torage throws Error
  • Loading branch information
vitorverasm committed Jan 26, 2021
1 parent 6dd9133 commit 7eb911f
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions src/infra/storage/local-storage-adapter.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import {Storage} from '@/data/protocols/storage/storage';
import {StorageGetError} from '@/domain/errors/storage-get-error';
import {StorageSetError} from '@/domain/errors/storage-set-error';
import {
StorageClearError,
StorageGetError,
StorageSetError,
} from '@/domain/errors';
import AsyncStorage from '@react-native-async-storage/async-storage';

export class LocalStorageAdapter implements Storage<string> {
Expand All @@ -20,6 +23,10 @@ export class LocalStorageAdapter implements Storage<string> {
}
}
async clear(key: string): Promise<void> {
await AsyncStorage.removeItem(key);
try {
await AsyncStorage.removeItem(key);
} catch (error) {
throw new StorageClearError();
}
}
}

0 comments on commit 7eb911f

Please sign in to comment.