@@ -307,22 +307,42 @@ export class DraftService implements Disposable {
307307
308308 @log ( )
309309 async getDraft ( id : string ) : Promise < Draft > {
310+ const scope = getLogScope ( ) ;
311+
310312 type Result = { data : DraftResponse } ;
311313
312314 const [ rspResult , changesetsResult ] = await Promise . allSettled ( [
313315 this . connection . fetchGkDevApi ( `v1/drafts/${ id } ` , { method : 'GET' } ) ,
314316 this . getChangesets ( id ) ,
315317 ] ) ;
316318
317- const rsp = getSettledValue ( rspResult ) ;
319+ if ( rspResult . status === 'rejected' ) {
320+ Logger . error ( rspResult . reason , scope , `Unable to open draft '${ id } ': ${ rspResult . reason } ` ) ;
321+ throw new Error ( `Unable to open draft '${ id } ': ${ rspResult . reason } ` ) ;
322+ }
323+
324+ if ( changesetsResult . status === 'rejected' ) {
325+ Logger . error (
326+ changesetsResult . reason ,
327+ scope ,
328+ `Unable to open changeset for draft '${ id } ': ${ changesetsResult . reason } ` ,
329+ ) ;
330+ throw new Error ( `Unable to open changesets for draft '${ id } ': ${ changesetsResult . reason } ` ) ;
331+ }
318332
333+ const rsp = getSettledValue ( rspResult ) ! ;
319334 if ( rsp ?. ok === false ) {
320- Logger . error ( undefined , `Getting draft failed: (${ rsp . status } ) ${ rsp . statusText } ` ) ;
321- throw new Error ( rsp . statusText ) ;
335+ const json = ( await rsp . json ( ) ) as { error ?: { message ?: string } } | undefined ;
336+ Logger . error (
337+ undefined ,
338+ scope ,
339+ `Unable to open draft '${ id } ': (${ rsp . status } ) ${ json ?. error ?. message ?? rsp . statusText } ` ,
340+ ) ;
341+ throw new Error ( json ?. error ?. message ?? rsp . statusText ) ;
322342 }
323343
324344 const draft = ( ( await rsp . json ( ) ) as Result ) . data ;
325- const changesets = getSettledValue ( changesetsResult ) ?? [ ] ;
345+ const changesets = getSettledValue ( changesetsResult ) ! ;
326346
327347 const author : Draft [ 'author' ] = {
328348 id : draft . createdBy ,
@@ -394,62 +414,81 @@ export class DraftService implements Disposable {
394414
395415 @log ( )
396416 async getChangesets ( id : string ) : Promise < DraftChangeset [ ] > {
397- type Result = { data : DraftChangesetResponse [ ] } ;
398-
399- const rsp = await this . connection . fetchGkDevApi ( `/v1/drafts/${ id } /changesets` , { method : 'GET' } ) ;
400-
401- const changeset = ( ( await rsp . json ( ) ) as Result ) . data ;
417+ const scope = getLogScope ( ) ;
402418
403- const changesets : DraftChangeset [ ] = [ ] ;
404- for ( const c of changeset ) {
405- const patches : DraftPatch [ ] = [ ] ;
419+ type Result = { data : DraftChangesetResponse [ ] } ;
406420
407- // const repoPromises = Promise.allSettled(c.patches.map(p => this.getRepositoryForGkId(p.gitRepositoryId)));
421+ try {
422+ const rsp = await this . connection . fetchGkDevApi ( `/v1/drafts/${ id } /changesets` , { method : 'GET' } ) ;
423+ if ( rsp ?. ok === false ) {
424+ const json = ( await rsp . json ( ) ) as { error ?: { message ?: string } } | undefined ;
425+ Logger . error (
426+ undefined ,
427+ scope ,
428+ `Unable to open changesets for draft '${ id } ': (${ rsp . status } ) ${
429+ json ?. error ?. message ?? rsp . statusText
430+ } `,
431+ ) ;
432+ throw new Error ( json ?. error ?. message ?? rsp . statusText ) ;
433+ }
408434
409- for ( const p of c . patches ) {
410- // const repoData = await this.getRepositoryData(p.gitRepositoryId);
411- // const repo = await this.container.git.findMatchingRepository({
412- // firstSha: repoData.initialCommitSha,
413- // remoteUrl: repoData.remote?.url,
414- // });
435+ const changeset = ( ( await rsp . json ( ) ) as Result ) . data ;
436+
437+ const changesets : DraftChangeset [ ] = [ ] ;
438+ for ( const c of changeset ) {
439+ const patches : DraftPatch [ ] = [ ] ;
440+
441+ // const repoPromises = Promise.allSettled(c.patches.map(p => this.getRepositoryForGkId(p.gitRepositoryId)));
442+
443+ for ( const p of c . patches ) {
444+ // const repoData = await this.getRepositoryData(p.gitRepositoryId);
445+ // const repo = await this.container.git.findMatchingRepository({
446+ // firstSha: repoData.initialCommitSha,
447+ // remoteUrl: repoData.remote?.url,
448+ // });
449+
450+ patches . push ( {
451+ type : 'cloud' ,
452+ id : p . id ,
453+ createdAt : new Date ( p . createdAt ) ,
454+ updatedAt : new Date ( p . updatedAt ?? p . createdAt ) ,
455+ draftId : p . draftId ,
456+ changesetId : p . changesetId ,
457+ userId : c . userId ,
458+
459+ baseBranchName : p . baseBranchName ,
460+ baseRef : p . baseCommitSha ,
461+ gkRepositoryId : p . gitRepositoryId ,
462+ secureLink : p . secureDownloadData ,
463+
464+ // // TODO@eamodio FIX THIS
465+ // repository: repo,
466+ // repoData: repoData,
467+ } ) ;
468+ }
415469
416- patches . push ( {
417- type : 'cloud' ,
418- id : p . id ,
419- createdAt : new Date ( p . createdAt ) ,
420- updatedAt : new Date ( p . updatedAt ?? p . createdAt ) ,
421- draftId : p . draftId ,
422- changesetId : p . changesetId ,
470+ changesets . push ( {
471+ id : c . id ,
472+ createdAt : new Date ( c . createdAt ) ,
473+ updatedAt : new Date ( c . updatedAt ?? c . createdAt ) ,
474+ draftId : c . draftId ,
475+ parentChangesetId : c . parentChangesetId ,
423476 userId : c . userId ,
424477
425- baseBranchName : p . baseBranchName ,
426- baseRef : p . baseCommitSha ,
427- gkRepositoryId : p . gitRepositoryId ,
428- secureLink : p . secureDownloadData ,
478+ gitUserName : c . gitUserName ,
479+ gitUserEmail : c . gitUserEmail ,
429480
430- // // TODO@eamodio FIX THIS
431- // repository: repo,
432- // repoData: repoData,
481+ deepLinkUrl : c . deepLink ,
482+ patches : patches ,
433483 } ) ;
434484 }
435485
436- changesets . push ( {
437- id : c . id ,
438- createdAt : new Date ( c . createdAt ) ,
439- updatedAt : new Date ( c . updatedAt ?? c . createdAt ) ,
440- draftId : c . draftId ,
441- parentChangesetId : c . parentChangesetId ,
442- userId : c . userId ,
443-
444- gitUserName : c . gitUserName ,
445- gitUserEmail : c . gitUserEmail ,
486+ return changesets ;
487+ } catch ( ex ) {
488+ Logger . error ( ex , scope ) ;
446489
447- deepLinkUrl : c . deepLink ,
448- patches : patches ,
449- } ) ;
490+ throw ex ;
450491 }
451-
452- return changesets ;
453492 }
454493
455494 @log ( )
0 commit comments