Skip to content

Commit aa0d99f

Browse files
authored
Fixed failure with no generated draft, recognize faulted and canceled draft statuses (#36)
1 parent 87db745 commit aa0d99f

File tree

3 files changed

+42
-13
lines changed

3 files changed

+42
-13
lines changed

src/scripture-forge/src/home/project-table.component.tsx

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import {
2121
SlingshotDraftSetupState,
2222
SlingshotProjectConnectionState,
2323
} from 'scripture-forge';
24+
import { isDraftCurrentlyGenerating } from '../utils';
2425

2526
type SortConfig = {
2627
key: 'fullName' | 'language' | 'draftSetupState' | 'action';
@@ -138,8 +139,7 @@ export default function ProjectTable({
138139
const draftInfo = await draftInfoPdp.getDraftInfo(undefined);
139140

140141
if (
141-
draftInfo.currentlyGeneratingDraftStatus &&
142-
draftInfo.currentlyGeneratingDraftStatus.state !== 'COMPLETED' &&
142+
isDraftCurrentlyGenerating(draftInfo.currentlyGeneratingDraftStatus?.state) &&
143143
!pollTimeout
144144
)
145145
pollTimeout = setTimeout(() => {
@@ -247,9 +247,9 @@ export default function ProjectTable({
247247

248248
const buildTableDraftSetupStateElement = (projectInfo: ProjectInfo) => {
249249
const { connectionState, draftSetupState } = projectInfo.draftInfo;
250-
const isDraftGenerating =
251-
projectInfo.draftInfo.currentlyGeneratingDraftStatus &&
252-
projectInfo.draftInfo.currentlyGeneratingDraftStatus.state !== 'COMPLETED';
250+
const isDraftGenerating = isDraftCurrentlyGenerating(
251+
projectInfo.draftInfo.currentlyGeneratingDraftStatus?.state,
252+
);
253253

254254
let statusText = '';
255255

@@ -339,9 +339,9 @@ export default function ProjectTable({
339339
</div>
340340
);
341341
case 'connected': {
342-
const isDraftGenerating =
343-
projectInfo.draftInfo.currentlyGeneratingDraftStatus &&
344-
projectInfo.draftInfo.currentlyGeneratingDraftStatus.state !== 'COMPLETED';
342+
const isDraftGenerating = isDraftCurrentlyGenerating(
343+
projectInfo.draftInfo.currentlyGeneratingDraftStatus?.state,
344+
);
345345

346346
if (draftSetupState === 'hasFinishedDraft')
347347
return (

src/scripture-forge/src/projects/slingshot-project-data-provider-engine.model.ts

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -136,10 +136,13 @@ export default class SlingshotProjectDataProviderEngine
136136
`${this.projectInfo.projectId} SF Project endpoint indicated there is a finished draft but received response for last completed ${lastCompletedDraftStatus} and for currently generating ${currentlyGeneratingDraftStatus}! Not sure what to do with this`,
137137
);
138138

139-
if (lastCompletedDraftStatus === StatusCodes.NO_CONTENT) {
139+
if (
140+
lastCompletedDraftStatus === StatusCodes.NO_CONTENT ||
141+
lastCompletedDraftStatus === StatusCodes.NOT_FOUND
142+
) {
140143
if (draftSetupState === 'hasFinishedDraft')
141144
throw new Error(
142-
`${this.projectInfo.projectId} SF Project endpoint indicated there is a finished draft but received no content response for last completed ${lastCompletedDraftStatus}! Not sure what to do with this`,
145+
`${this.projectInfo.projectId} SF Project endpoint indicated there is a finished draft but received non-content response for last completed ${lastCompletedDraftStatus}! Not sure what to do with this`,
143146
);
144147
} else if (typeof lastCompletedDraftStatus === 'number')
145148
throw new Error(
@@ -150,20 +153,27 @@ export default class SlingshotProjectDataProviderEngine
150153

151154
if (
152155
typeof currentlyGeneratingDraftStatus === 'number' &&
153-
currentlyGeneratingDraftStatus !== StatusCodes.NO_CONTENT
156+
currentlyGeneratingDraftStatus !== StatusCodes.NO_CONTENT &&
157+
currentlyGeneratingDraftStatus !== StatusCodes.NOT_FOUND
154158
)
155159
throw new Error(
156160
`Requesting currently generating draft status for SF project id ${this.projectInfo.projectId} returned error code ${lastCompletedDraftStatus}! Not sure what to do with this`,
157161
);
158162

159-
if (lastCompletedDraftStatus !== StatusCodes.NO_CONTENT) {
163+
if (
164+
lastCompletedDraftStatus !== StatusCodes.NO_CONTENT &&
165+
lastCompletedDraftStatus !== StatusCodes.NOT_FOUND
166+
) {
160167
if (draftSetupState === 'draftingNotAvailable')
161168
throw new Error(
162169
`${this.projectInfo.projectId} SF Project endpoint indicated drafting is not available, but we received draft information from last completed! Not sure what to do with this`,
163170
);
164171
draftInfo.lastCompletedDraftStatus = lastCompletedDraftStatus;
165172
}
166-
if (currentlyGeneratingDraftStatus !== StatusCodes.NO_CONTENT) {
173+
if (
174+
currentlyGeneratingDraftStatus !== StatusCodes.NO_CONTENT &&
175+
currentlyGeneratingDraftStatus !== StatusCodes.NOT_FOUND
176+
) {
167177
if (draftSetupState === 'draftingNotAvailable')
168178
throw new Error(
169179
`${this.projectInfo.projectId} SF Project endpoint indicated drafting is not available, but we received draft information from currently generating! Not sure what to do with this`,

src/scripture-forge/src/utils.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import { SlingshotDraftBuildState } from 'scripture-forge';
2+
3+
/**
4+
* Whether a draft state indicates the draft is currently generating as opposed to finished in some
5+
* way (success or otherwise)
6+
*
7+
* @param draftState The state of the draft build
8+
* @returns `true` if currently generating. `false` otherwise including if state is `undefined`.
9+
*/
10+
export function isDraftCurrentlyGenerating(
11+
draftState: SlingshotDraftBuildState | undefined,
12+
): boolean {
13+
return (
14+
!!draftState &&
15+
draftState !== 'COMPLETED' &&
16+
draftState !== 'FAULTED' &&
17+
draftState !== 'CANCELED'
18+
);
19+
}

0 commit comments

Comments
 (0)