@@ -16,10 +16,12 @@ import { observer } from 'mobx-react';
1616import {
1717 EditorId ,
1818 EditorValues ,
19+ GenericDialogType ,
1920 GistActionState ,
2021 GistActionType ,
2122 PACKAGE_NAME ,
2223} from '../../interfaces' ;
24+ import { FIDDLE_GIST_DESCRIPTION_PLACEHOLDER } from '../constants' ;
2325import { AppState } from '../state' ;
2426import { ensureRequiredFiles } from '../utils/editor-utils' ;
2527import { getOctokit } from '../utils/octokit' ;
@@ -98,7 +100,7 @@ export const GistActionButton = observer(
98100 }
99101
100102 private getFiddleDescriptionFromUser ( ) : Promise < string | undefined > {
101- const placeholder = 'Electron Fiddle Gist' as const ;
103+ const placeholder = FIDDLE_GIST_DESCRIPTION_PLACEHOLDER ;
102104 return this . props . appState . showInputDialog ( {
103105 defaultInput : placeholder ,
104106 label : 'Please provide a brief description for your Fiddle Gist' ,
@@ -156,11 +158,23 @@ export const GistActionButton = observer(
156158 } catch ( error : any ) {
157159 console . warn ( `Could not publish gist` , { error } ) ;
158160
159- window . ElectronFiddle . showWarningDialog ( {
160- message :
161- 'Publishing Fiddle to GitHub failed. Are you connected to the Internet?' ,
162- detail : `GitHub encountered the following error: ${ error . message } ` ,
163- } ) ;
161+ if ( error . status === 401 || error . status === 403 ) {
162+ const { confirm } = await this . props . appState . showGenericDialog ( {
163+ label : `Publishing Fiddle to GitHub failed. GitHub encountered the following error: ${ error . message } ` ,
164+ ok : 'Update token' ,
165+ cancel : 'Close' ,
166+ type : GenericDialogType . warning ,
167+ wantsInput : false ,
168+ } ) ;
169+
170+ if ( confirm ) {
171+ this . showGitHubTokenSettings ( ) ;
172+ }
173+ } else {
174+ await this . props . appState . showErrorDialog (
175+ `Publishing Fiddle to GitHub failed. Are you connected to the Internet? GitHub encountered the following error: ${ error . message } ` ,
176+ ) ;
177+ }
164178
165179 return false ;
166180 }
@@ -230,12 +244,23 @@ export const GistActionButton = observer(
230244 } catch ( error : any ) {
231245 console . warn ( `Could not update gist` , { error } ) ;
232246
233- window . ElectronFiddle . showWarningDialog ( {
234- message :
235- 'Updating Fiddle Gist failed. Are you connected to the Internet and is this your Gist?' ,
236- detail : `GitHub encountered the following error: ${ error . message } ` ,
237- buttons : [ 'Ok' ] ,
238- } ) ;
247+ if ( error . status === 401 || error . status === 403 ) {
248+ const { confirm } = await this . props . appState . showGenericDialog ( {
249+ label : `Updating Fiddle Gist failed. GitHub encountered the following error: ${ error . message } ` ,
250+ ok : 'Update token' ,
251+ cancel : 'Close' ,
252+ type : GenericDialogType . warning ,
253+ wantsInput : false ,
254+ } ) ;
255+
256+ if ( confirm ) {
257+ this . showGitHubTokenSettings ( ) ;
258+ }
259+ } else {
260+ await this . props . appState . showErrorDialog (
261+ `Updating Fiddle Gist failed. Are you connected to the Internet? GitHub encountered the following error: ${ error . message } ` ,
262+ ) ;
263+ }
239264 }
240265
241266 appState . activeGistAction = GistActionState . none ;
@@ -262,11 +287,23 @@ export const GistActionButton = observer(
262287 } catch ( error : any ) {
263288 console . warn ( `Could not delete gist` , { error } ) ;
264289
265- window . ElectronFiddle . showWarningDialog ( {
266- message :
267- 'Deleting Fiddle Gist failed. Are you connected to the Internet, is this your Gist, and have you loaded it?' ,
268- detail : `GitHub encountered the following error: ${ error . message } ` ,
269- } ) ;
290+ if ( error . status === 401 || error . status === 403 ) {
291+ const { confirm } = await this . props . appState . showGenericDialog ( {
292+ label : `Deleting Fiddle Gist failed. GitHub encountered the following error: ${ error . message } ` ,
293+ ok : 'Update token' ,
294+ cancel : 'Close' ,
295+ type : GenericDialogType . warning ,
296+ wantsInput : false ,
297+ } ) ;
298+
299+ if ( confirm ) {
300+ this . showGitHubTokenSettings ( ) ;
301+ }
302+ } else {
303+ await this . props . appState . showErrorDialog (
304+ `Deleting Fiddle Gist failed. Are you connected to the Internet? GitHub encountered the following error: ${ error . message } ` ,
305+ ) ;
306+ }
270307 }
271308
272309 appState . gistId = undefined ;
@@ -455,5 +492,10 @@ export const GistActionButton = observer(
455492 . map ( ( [ id , content ] ) => [ id , { filename : id , content } ] ) ,
456493 ) ;
457494 } ;
495+
496+ private showGitHubTokenSettings ( ) {
497+ this . props . appState . toggleSettings ( ) ;
498+ this . props . appState . toggleAuthDialog ( ) ;
499+ }
458500 } ,
459501) ;
0 commit comments