fix(application): enhance application reload process with error handling and Docker container management

- Added mechanizeDockerContainer function to manage Docker container state during application reload.
- Improved error handling to update application status on failure and provide more informative error messages.
- Refactored authorization check to throw an error if the user is not authorized to reload the application.
This commit is contained in:
Mauricio Siu 2025-04-06 03:05:46 -06:00
parent 48ec0a74ad
commit 2352939e87

View File

@ -33,6 +33,7 @@ import {
findApplicationById,
findProjectById,
getApplicationStats,
mechanizeDockerContainer,
readConfig,
readRemoteConfig,
removeDeployments,
@ -132,28 +133,36 @@ export const applicationRouter = createTRPCRouter({
.input(apiReloadApplication)
.mutation(async ({ input, ctx }) => {
const application = await findApplicationById(input.applicationId);
if (
application.project.organizationId !== ctx.session.activeOrganizationId
) {
try {
if (
application.project.organizationId !==
ctx.session.activeOrganizationId
) {
throw new TRPCError({
code: "UNAUTHORIZED",
message: "You are not authorized to reload this application",
});
}
if (application.serverId) {
await stopServiceRemote(application.serverId, input.appName);
} else {
await stopService(input.appName);
}
await updateApplicationStatus(input.applicationId, "idle");
await mechanizeDockerContainer(application);
await updateApplicationStatus(input.applicationId, "done");
return true;
} catch (error) {
await updateApplicationStatus(input.applicationId, "error");
throw new TRPCError({
code: "UNAUTHORIZED",
message: "You are not authorized to reload this application",
code: "INTERNAL_SERVER_ERROR",
message: "Error reloading application",
cause: error,
});
}
if (application.serverId) {
await stopServiceRemote(application.serverId, input.appName);
} else {
await stopService(input.appName);
}
await updateApplicationStatus(input.applicationId, "idle");
if (application.serverId) {
await startServiceRemote(application.serverId, input.appName);
} else {
await startService(input.appName);
}
await updateApplicationStatus(input.applicationId, "done");
return true;
}),
delete: protectedProcedure