@@ -27,6 +27,7 @@ import {
2727import { EnvironmentVariablesRepository } from "~/v3/environmentVariables/environmentVariablesRepository.server" ;
2828import { isReservedForExternalSync } from "~/v3/environmentVariableRules.server" ;
2929import { boundedIn } from "@trigger.dev/database" ;
30+ import { toVercelApiError , type VercelApiError } from "~/v3/vercel/vercelApiError" ;
3031import {
3132 callVercelWithRecovery ,
3233 wrapVercelCallWithRecovery ,
@@ -120,70 +121,7 @@ function extractCreateProjectEnvFailures(response: unknown): string[] {
120121// Error handling
121122// ---------------------------------------------------------------------------
122123
123- export type VercelApiError = {
124- message : string ;
125- authInvalid : boolean ;
126- } ;
127-
128- const VercelErrorSchema = z . union ( [
129- z . object ( { status : z . number ( ) } ) ,
130- z . object ( { response : z . object ( { status : z . number ( ) } ) } ) ,
131- z . object ( { statusCode : z . number ( ) } ) ,
132- ] ) ;
133-
134- function extractVercelErrorStatus ( error : unknown ) : number | null {
135- if ( error && typeof error === "object" && "status" in error ) {
136- const parsed = VercelErrorSchema . safeParse ( error ) ;
137- if ( parsed . success && "status" in parsed . data ) {
138- return parsed . data . status ;
139- }
140- }
141-
142- if ( error && typeof error === "object" && "response" in error ) {
143- const parsed = VercelErrorSchema . safeParse ( error ) ;
144- if ( parsed . success && "response" in parsed . data ) {
145- return parsed . data . response . status ;
146- }
147- }
148-
149- if ( error && typeof error === "object" && "statusCode" in error ) {
150- const parsed = VercelErrorSchema . safeParse ( error ) ;
151- if ( parsed . success && "statusCode" in parsed . data ) {
152- return parsed . data . statusCode ;
153- }
154- }
155-
156- if ( typeof error === "string" ) {
157- if ( error . includes ( "401" ) ) return 401 ;
158- if ( error . includes ( "403" ) ) return 403 ;
159- }
160-
161- return null ;
162- }
163-
164- function isVercelAuthError ( error : unknown ) : boolean {
165- const status = extractVercelErrorStatus ( error ) ;
166- return status === 401 || status === 403 ;
167- }
168-
169- function toVercelApiError ( error : unknown ) : VercelApiError {
170- if ( isVercelApiErrorShape ( error ) ) return error ;
171- return {
172- message : error instanceof Error ? error . message : "Unknown error" ,
173- authInvalid : isVercelAuthError ( error ) ,
174- } ;
175- }
176-
177- function isVercelApiErrorShape ( error : unknown ) : error is VercelApiError {
178- return (
179- error !== null &&
180- typeof error === "object" &&
181- "message" in error &&
182- "authInvalid" in error &&
183- typeof ( error as VercelApiError ) . message === "string" &&
184- typeof ( error as VercelApiError ) . authInvalid === "boolean"
185- ) ;
186- }
124+ export type { VercelApiError } from "~/v3/vercel/vercelApiError" ;
187125// ---------------------------------------------------------------------------
188126// Schemas & token types
189127// ---------------------------------------------------------------------------
@@ -597,7 +535,10 @@ export class VercelIntegrationRepository {
597535 logger . warn ( "Failed to decrypt Vercel env var" , {
598536 projectId,
599537 envVarKey : env . key ,
600- error : result . error instanceof Error ? result . error . message : String ( result . error ) ,
538+ error : result . error . message ,
539+ errorType : result . error . errorType ,
540+ status : result . error . status ,
541+ authInvalid : result . error . authInvalid ,
601542 } ) ;
602543 return null ;
603544 }
@@ -784,10 +725,10 @@ export class VercelIntegrationRepository {
784725 projectId,
785726 envId,
786727 envKey,
787- error :
788- getResult . error instanceof Error
789- ? getResult . error . message
790- : String ( getResult . error ) ,
728+ error : getResult . error . message ,
729+ errorType : getResult . error . errorType ,
730+ status : getResult . error . status ,
731+ authInvalid : getResult . error . authInvalid ,
791732 } ) ;
792733 return null ;
793734 } )
@@ -2096,7 +2037,7 @@ export class VercelIntegrationRepository {
20962037 )
20972038 . map ( ( ) => ( { authInvalid : false } ) )
20982039 . orElse ( ( error ) => {
2099- const isAuthError = isVercelAuthError ( error ) ;
2040+ const isAuthError = toVercelApiError ( error ) . authInvalid ;
21002041 logger . error ( "Failed to uninstall Vercel integration" , {
21012042 installationId,
21022043 error : error instanceof Error ? error . message : "Unknown error" ,
0 commit comments