@@ -166,16 +166,29 @@ export const POST = withRouteHandler(async (request: NextRequest) => {
166166 }
167167
168168 resolvedWorkspaceId = authorization . workflow . workspaceId
169- billingAttribution =
170- auth . authType === AuthType . INTERNAL_JWT
171- ? requireBillingAttributionHeader ( request . headers , {
172- actorUserId : auth . userId ,
173- workspaceId : resolvedWorkspaceId ,
174- } )
175- : await resolveBillingAttribution ( {
176- actorUserId : auth . userId ,
177- workspaceId : resolvedWorkspaceId ,
178- } )
169+ try {
170+ billingAttribution =
171+ auth . authType === AuthType . INTERNAL_JWT
172+ ? requireBillingAttributionHeader ( request . headers , {
173+ actorUserId : auth . userId ,
174+ workspaceId : resolvedWorkspaceId ,
175+ } )
176+ : await resolveBillingAttribution ( {
177+ actorUserId : auth . userId ,
178+ workspaceId : resolvedWorkspaceId ,
179+ } )
180+ } catch ( error ) {
181+ const isInternalRequest = auth . authType === AuthType . INTERNAL_JWT
182+ logger . error ( `[${ requestId } ] Failed to establish billing attribution` , { error } )
183+ return NextResponse . json (
184+ {
185+ error : isInternalRequest
186+ ? 'Invalid billing attribution'
187+ : 'Failed to resolve billing attribution' ,
188+ } ,
189+ { status : isInternalRequest ? 400 : 500 }
190+ )
191+ }
179192
180193 try {
181194 await assertPermissionsAllowed ( {
0 commit comments