File tree Expand file tree Collapse file tree 4 files changed +29
-4
lines changed
Expand file tree Collapse file tree 4 files changed +29
-4
lines changed Original file line number Diff line number Diff line change 11import { config } from '../../config.js' ;
22import { LoginHelper } from '../../connect/login-helper.js' ;
33import { CloudDocument } from './types.js' ;
4+ import { UnauthorizedError } from '../../common/errors.js' ;
45
56export const DashboardApiClient = {
67 async getDocument ( id : string ) : Promise < CloudDocument > {
@@ -35,7 +36,13 @@ export const DashboardApiClient = {
3536 ) ;
3637
3738 if ( ! res . ok ) {
39+ console . log ( 'Request not okay' , res . status )
3840 const message = await res . text ( ) ;
41+ if ( res . status === 401 ) {
42+ console . log ( 'Unauthorized' ) ;
43+ throw new UnauthorizedError ( { requestName : 'getDefaultDocumentId' } ) ;
44+ }
45+
3946 throw new Error ( message ) ;
4047 }
4148
Original file line number Diff line number Diff line change @@ -142,6 +142,20 @@ export class SyntaxError extends CodifyError {
142142 }
143143}
144144
145+ export class UnauthorizedError extends CodifyError {
146+ name = 'UnauthorizedError'
147+ requestName ?: string
148+
149+ constructor ( props : Omit < RemoveErrorMethods < UnauthorizedError > , 'message' > ) {
150+ super ( `Unauthorized request to Codify. ${ props . requestName ?? '' } ` )
151+ Object . assign ( this , props ) ;
152+ }
153+
154+ formattedMessage ( ) : string {
155+ return this . message
156+ }
157+ }
158+
145159export function prettyPrintError ( error : unknown ) : void {
146160 if ( error instanceof CodifyError ) {
147161 return console . error ( chalk . red ( error . formattedMessage ( ) ) ) ;
Original file line number Diff line number Diff line change @@ -107,7 +107,7 @@ export class PluginInitOrchestrator {
107107 }
108108
109109 if ( LoginHelper . get ( ) ?. isLoggedIn ) {
110- return DashboardApiClient . getDefaultDocumentId ( ) ;
110+ return ( await DashboardApiClient . getDefaultDocumentId ( ) ) ?? undefined ;
111111 }
112112
113113 if ( args . allowEmptyProject ) {
Original file line number Diff line number Diff line change 11import { Config } from '@oclif/core' ;
2- import { randomBytes } from 'node:crypto' ;
32import open from 'open' ;
43
54import { DashboardApiClient } from '../api/dashboard/index.js' ;
@@ -9,7 +8,6 @@ import { ConnectOrchestrator } from './connect.js';
98import { LoginOrchestrator } from './login.js' ;
109
1110export class EditOrchestrator {
12- static rootCommand : string ;
1311
1412 static async run ( oclifConfig : Config ) {
1513 const login = LoginHelper . get ( ) ?. isLoggedIn ;
@@ -18,7 +16,13 @@ export class EditOrchestrator {
1816 await LoginOrchestrator . run ( ) ;
1917 }
2018
21- const defaultDocumentId = await DashboardApiClient . getDefaultDocumentId ( ) ;
19+ let defaultDocumentId : null | string = null ;
20+ try {
21+ defaultDocumentId = await DashboardApiClient . getDefaultDocumentId ( ) ;
22+ } catch {
23+ console . warn ( 'Mismatch accounts between local and dashboard. Cannot open default document' )
24+ }
25+
2226 const url = defaultDocumentId
2327 ? `${ config . dashboardUrl } /file/${ defaultDocumentId } `
2428 : config . dashboardUrl ;
You can’t perform that action at this time.
0 commit comments