Skip to content

Commit

Permalink
fix: check for valid connection (#428)
Browse files Browse the repository at this point in the history
* fix: check for valid connection

* refactor: remove unused import
  • Loading branch information
stew-ro authored Jul 20, 2020
1 parent 162a766 commit 9cb6c58
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 4 deletions.
9 changes: 7 additions & 2 deletions src/providers/storage/azureBlobStorage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,13 @@ export class AzureBlobStorage implements IStorageProvider {

public async isValidProjectConnection() {
try {
await new ServiceURL(this.options.sas, StorageURL.newPipeline(this.getCredential())).getAccountInfo(Aborter.none);
return (true);
return await new ServiceURL(this.options.sas, StorageURL.newPipeline(this.getCredential())).getAccountInfo(Aborter.timeout(5000))
.then(() => {
return true;
})
.catch(() => {
return false;
})
} catch {
return (false);
}
Expand Down
2 changes: 1 addition & 1 deletion src/react/components/pages/homepage/homePage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ export default class HomePage extends React.Component<IHomePageProps, IHomePageS
let projectStr: string;
try {
const projectService = new ProjectService();
if (!(await projectService.isValidProjectConnection(project))) {
if (!(await projectService.isValidProjectConnection(decryptedProject))) {
return;
}
projectStr = await storageProvider.readText(
Expand Down
7 changes: 6 additions & 1 deletion src/services/projectService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,12 @@ export default class ProjectService implements IProjectService {

public async isValidProjectConnection(project: IProject): Promise<boolean> {
const storageProvider = StorageProviderFactory.createFromConnection(project.sourceConnection);
const isValid = await storageProvider.isValidProjectConnection();
let isValid;
try {
isValid = await storageProvider.isValidProjectConnection();
} catch {
isValid = false;
}
if (!isValid) {
if (project.sourceConnection.providerType === "localFileSystemProxy") {
await toast.error(interpolate(strings.connections.providers.local.invalidFolderMessage, {project}));
Expand Down

0 comments on commit 9cb6c58

Please sign in to comment.