This repository has been archived by the owner on Oct 23, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 224
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: try harder to get the very latest data when saving explicitly
- Loading branch information
Showing
3 changed files
with
45 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import * as Message from '../message'; | ||
import * as Model from '../model'; | ||
import { Sender } from '../sender/server'; | ||
import * as Types from '../types'; | ||
import * as uuid from 'uuid'; | ||
|
||
export async function requestProject(sender: Sender): Promise<Model.Project> { | ||
const projectResponse = await sender.request<Message.ProjectRequestResponsePair>( | ||
{ | ||
id: uuid.v4(), | ||
type: Message.MessageType.ProjectRequest, | ||
payload: undefined | ||
}, | ||
Message.MessageType.ProjectResponse | ||
); | ||
|
||
if (projectResponse.payload.status === Types.ProjectStatus.None) { | ||
throw new Error('There must be an opened project before oppening a library'); | ||
} | ||
|
||
if ( | ||
projectResponse.payload.status === Types.ProjectStatus.Error || | ||
projectResponse.payload.status !== Types.ProjectStatus.Ok || | ||
typeof projectResponse.payload.data === 'undefined' | ||
) { | ||
throw new Error('Error while importing library'); | ||
} | ||
|
||
return Model.Project.from(projectResponse.payload.data); | ||
} | ||
|
||
export async function requestProjectSafely(sender: Sender): Promise<Model.Project | undefined> { | ||
try { | ||
return await requestProject(sender); | ||
} catch (err) { | ||
return; | ||
} | ||
} |