Skip to content

Commit 2c5a65c

Browse files
committed
address bugbot comments
1 parent 7f5357c commit 2c5a65c

File tree

7 files changed

+20
-13
lines changed

7 files changed

+20
-13
lines changed

apps/sim/app/api/folders/[id]/route.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,9 @@ export async function DELETE(
151151
})
152152

153153
if (!result.success) {
154-
return NextResponse.json({ error: result.error }, { status: 400 })
154+
const status =
155+
result.errorCode === 'not_found' ? 404 : result.errorCode === 'validation' ? 400 : 500
156+
return NextResponse.json({ error: result.error }, { status })
155157
}
156158

157159
return NextResponse.json({

apps/sim/app/api/workflows/[id]/route.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -212,18 +212,17 @@ export async function DELETE(
212212
})
213213
}
214214

215-
const templateAction: 'delete' | 'orphan' =
216-
deleteTemplatesParam === 'delete' ? 'delete' : 'orphan'
217-
218215
const result = await performDeleteWorkflow({
219216
workflowId,
220217
userId,
221218
requestId,
222-
templateAction,
219+
templateAction: deleteTemplatesParam === 'delete' ? 'delete' : 'orphan',
223220
})
224221

225222
if (!result.success) {
226-
return NextResponse.json({ error: result.error }, { status: 400 })
223+
const status =
224+
result.errorCode === 'not_found' ? 404 : result.errorCode === 'validation' ? 400 : 500
225+
return NextResponse.json({ error: result.error }, { status })
227226
}
228227

229228
const elapsed = Date.now() - startTime

apps/sim/lib/workflows/orchestration/deploy.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import {
1111
restorePreviousVersionWebhooks,
1212
saveTriggerWebhooksForDeploy,
1313
} from '@/lib/webhooks/deploy'
14+
import type { OrchestrationErrorCode } from '@/lib/workflows/orchestration/types'
1415
import {
1516
activateWorkflowVersion,
1617
activateWorkflowVersionById,
@@ -43,15 +44,13 @@ export interface PerformFullDeployParams {
4344
actorId?: string
4445
}
4546

46-
export type DeployErrorCode = 'validation' | 'not_found' | 'internal'
47-
4847
export interface PerformFullDeployResult {
4948
success: boolean
5049
deployedAt?: Date
5150
version?: number
5251
deploymentVersionId?: string
5352
error?: string
54-
errorCode?: DeployErrorCode
53+
errorCode?: OrchestrationErrorCode
5554
warnings?: string[]
5655
}
5756

@@ -306,7 +305,7 @@ export interface PerformActivateVersionResult {
306305
success: boolean
307306
deployedAt?: Date
308307
error?: string
309-
errorCode?: DeployErrorCode
308+
errorCode?: OrchestrationErrorCode
310309
warnings?: string[]
311310
}
312311

apps/sim/lib/workflows/orchestration/folder-lifecycle.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { createLogger } from '@sim/logger'
44
import { and, eq, isNull } from 'drizzle-orm'
55
import { AuditAction, AuditResourceType, recordAudit } from '@/lib/audit/log'
66
import { archiveWorkflowsByIdsInWorkspace } from '@/lib/workflows/lifecycle'
7+
import type { OrchestrationErrorCode } from '@/lib/workflows/orchestration/types'
78

89
const logger = createLogger('FolderLifecycle')
910

@@ -101,6 +102,7 @@ export interface PerformDeleteFolderParams {
101102
export interface PerformDeleteFolderResult {
102103
success: boolean
103104
error?: string
105+
errorCode?: OrchestrationErrorCode
104106
deletedItems?: { folders: number; workflows: number }
105107
}
106108

@@ -125,6 +127,7 @@ export async function performDeleteFolder(
125127
return {
126128
success: false,
127129
error: 'Cannot delete folder containing the only workflow(s) in the workspace',
130+
errorCode: 'validation',
128131
}
129132
}
130133

apps/sim/lib/workflows/orchestration/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ export {
77
performChatUndeploy,
88
} from './chat-deploy'
99
export {
10-
type DeployErrorCode,
1110
type PerformActivateVersionParams,
1211
type PerformActivateVersionResult,
1312
type PerformFullDeployParams,
@@ -23,6 +22,7 @@ export {
2322
type PerformDeleteFolderResult,
2423
performDeleteFolder,
2524
} from './folder-lifecycle'
25+
export type { OrchestrationErrorCode } from './types'
2626
export {
2727
type PerformDeleteWorkflowParams,
2828
type PerformDeleteWorkflowResult,
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export type OrchestrationErrorCode = 'validation' | 'not_found' | 'internal'

apps/sim/lib/workflows/orchestration/workflow-lifecycle.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { and, eq, isNull } from 'drizzle-orm'
55
import { AuditAction, AuditResourceType, recordAudit } from '@/lib/audit/log'
66
import { generateRequestId } from '@/lib/core/utils/request'
77
import { archiveWorkflow } from '@/lib/workflows/lifecycle'
8+
import type { OrchestrationErrorCode } from '@/lib/workflows/orchestration/types'
89

910
const logger = createLogger('WorkflowLifecycle')
1011

@@ -23,6 +24,7 @@ export interface PerformDeleteWorkflowParams {
2324
export interface PerformDeleteWorkflowResult {
2425
success: boolean
2526
error?: string
27+
errorCode?: OrchestrationErrorCode
2628
}
2729

2830
/**
@@ -45,7 +47,7 @@ export async function performDeleteWorkflow(
4547
.limit(1)
4648

4749
if (!workflowRecord) {
48-
return { success: false, error: 'Workflow not found' }
50+
return { success: false, error: 'Workflow not found', errorCode: 'not_found' }
4951
}
5052

5153
if (!skipLastWorkflowGuard && workflowRecord.workspaceId) {
@@ -58,6 +60,7 @@ export async function performDeleteWorkflow(
5860
return {
5961
success: false,
6062
error: 'Cannot delete the only workflow in the workspace',
63+
errorCode: 'validation',
6164
}
6265
}
6366
}
@@ -92,7 +95,7 @@ export async function performDeleteWorkflow(
9295

9396
const archiveResult = await archiveWorkflow(workflowId, { requestId })
9497
if (!archiveResult.workflow) {
95-
return { success: false, error: 'Workflow not found' }
98+
return { success: false, error: 'Workflow not found', errorCode: 'not_found' }
9699
}
97100

98101
logger.info(`[${requestId}] Successfully archived workflow ${workflowId}`)

0 commit comments

Comments
 (0)