{"record":{"id":"12a32ec8af2c891b","repo":"alibaba/spring-ai-alibaba","slug":"app-component-delete-error","errorCode":"APP_COMPONENT_DELETE_ERROR","errorMessage":"Failed to delete component.","messagePattern":"Failed to delete component\\.","errorType":"error_code","errorClass":"BizException","httpStatus":500,"severity":"error","filePath":"spring-ai-alibaba-admin/spring-ai-alibaba-admin-server-start/src/main/java/com/alibaba/cloud/ai/studio/admin/builder/controller/AppComponentController.java","lineNumber":246,"sourceCode":"\n\t/**\n\t * Deletes an application component. Removes a component from the system by its unique\n\t * code.\n\t * @param code Unique code of the component to delete\n\t * @return Result containing boolean indicating successful deletion\n\t */\n\t@DeleteMapping(\"/{code}\")\n\tpublic Result<Boolean> deleteComponent(@PathVariable(\"code\") String code) {\n\t\tRequestContext context = RequestContextHolder.getRequestContext();\n\t\tif (StringUtils.isBlank(code)) {\n\t\t\tthrow new BizException(ErrorCode.MISSING_PARAMS.toError(\"code\"));\n\t\t}\n\t\tResult<Void> voidResult = appComponentService.deleteAppComponent(code);\n\t\tif (voidResult.isSuccess()) {\n\t\t\treturn Result.success(context.getRequestId(), true);\n\t\t}\n\t\telse {\n\t\t\tthrow new BizException(ErrorCode.APP_COMPONENT_DELETE_ERROR.toError());\n\t\t}\n\t}\n\n\t/**\n\t * Retrieves detailed information about a component by its unique code. Includes\n\t * merged configuration from both component and source application.\n\t * @param code Unique code of the component\n\t * @return Result containing detailed AppComponent information with merged\n\t * configuration\n\t */\n\t@GetMapping(\"/{code}/detail-by-code\")\n\tpublic Result<AppComponent> detailByCode(@PathVariable(\"code\") String code) {\n\n\t\tRequestContext context = RequestContextHolder.getRequestContext();\n\t\tif (StringUtils.isBlank(code)) {\n\t\t\tthrow new BizException(ErrorCode.MISSING_PARAMS.toError(\"code\"));\n\t\t}\n\t\ttry {","sourceCodeStart":228,"sourceCodeEnd":264,"githubUrl":"https://github.com/alibaba/spring-ai-alibaba/blob/f82da0b50f35744c13968191be2b1cd2452ef550/spring-ai-alibaba-admin/spring-ai-alibaba-admin-server-start/src/main/java/com/alibaba/cloud/ai/studio/admin/builder/controller/AppComponentController.java#L228-L264","documentation":"BizException thrown by AppComponentController.deleteComponent when appComponentService.deleteAppComponent returns a non-success Result. The request was well-formed but the deletion failed in the service/persistence layer (record missing, FK constraints, internal error).","triggerScenarios":"DELETE /{code} with a valid non-blank code that the service cannot delete: component code not found, dependent records referencing the component, or a database failure surfaced as an error Result.","commonSituations":"Deleting an already-deleted component; foreign-key constraints from apps referencing the component; DB connectivity issues.","solutions":["Check server logs for the underlying cause logged by the service before this exception.","Verify the component with that code still exists before deleting (idempotent handling on the client).","Remove or cascade references to the component that block deletion.","Confirm database connectivity and schema state, then retry."],"exampleFix":"// before\nResult<Void> r = appComponentService.deleteAppComponent(code);\nif (!r.isSuccess()) throw new BizException(ErrorCode.APP_COMPONENT_DELETE_ERROR.toError());\n// after: treat not-found as idempotent success\nAppComponent existing = appComponentService.getAppComponentByCode(code, null);\nif (existing == null) return Result.success(context.getRequestId(), true);\nResult<Void> r2 = appComponentService.deleteAppComponent(code);\nif (!r2.isSuccess()) throw new BizException(ErrorCode.APP_COMPONENT_DELETE_ERROR.toError());","handlingStrategy":"try-catch","validationCode":"const existing = await api.getComponentByCode(code);\nif (!existing) return true; // already gone, treat delete as idempotent success","typeGuard":"boolean isDeletable(AppComponent c) { return c != null && StringUtils.isNotBlank(c.getCode()); }","tryCatchPattern":"try {\n  const res = await api.deleteComponent(code);\n  if (!res.isSuccess) throw new BizError('APP_COMPONENT_DELETE_ERROR', res);\n} catch (e) {\n  if (e.code === 'APP_COMPONENT_DELETE_ERROR') {\n    // check dependencies/references, then retry or surface to user\n  }\n}","preventionTips":["Treat delete as idempotent: check existence first or accept 404-like outcomes.","Clean up dependent references before deleting a component.","Verify DB connectivity in health checks.","Log the service-level cause before throwing the generic BizException."],"tags":["rest-api","persistence","deletion","spring"],"backgroundTag":"database-write-failed","analyzedSha":"f82da0b50f35744c13968191be2b1cd2452ef550","analyzedAt":"2026-09-09T15:32:42.421Z","contentChangedAt":"2026-09-09T15:32:42.421Z","schemaVersion":2},"datasetVersion":"2026-09-14T11:17:12.474Z"}