@@ -33,6 +33,7 @@ import {
3333 findApplicationById ,
3434 findProjectById ,
3535 getApplicationStats ,
36+ mechanizeDockerContainer ,
3637 readConfig ,
3738 readRemoteConfig ,
3839 removeDeployments ,
@@ -132,28 +133,36 @@ export const applicationRouter = createTRPCRouter({
132133 . input ( apiReloadApplication )
133134 . mutation ( async ( { input, ctx } ) => {
134135 const application = await findApplicationById ( input . applicationId ) ;
135- if (
136- application . project . organizationId !== ctx . session . activeOrganizationId
137- ) {
136+
137+ try {
138+ if (
139+ application . project . organizationId !==
140+ ctx . session . activeOrganizationId
141+ ) {
142+ throw new TRPCError ( {
143+ code : "UNAUTHORIZED" ,
144+ message : "You are not authorized to reload this application" ,
145+ } ) ;
146+ }
147+
148+ if ( application . serverId ) {
149+ await stopServiceRemote ( application . serverId , input . appName ) ;
150+ } else {
151+ await stopService ( input . appName ) ;
152+ }
153+
154+ await updateApplicationStatus ( input . applicationId , "idle" ) ;
155+ await mechanizeDockerContainer ( application ) ;
156+ await updateApplicationStatus ( input . applicationId , "done" ) ;
157+ return true ;
158+ } catch ( error ) {
159+ await updateApplicationStatus ( input . applicationId , "error" ) ;
138160 throw new TRPCError ( {
139- code : "UNAUTHORIZED" ,
140- message : "You are not authorized to reload this application" ,
161+ code : "INTERNAL_SERVER_ERROR" ,
162+ message : "Error reloading application" ,
163+ cause : error ,
141164 } ) ;
142165 }
143- if ( application . serverId ) {
144- await stopServiceRemote ( application . serverId , input . appName ) ;
145- } else {
146- await stopService ( input . appName ) ;
147- }
148- await updateApplicationStatus ( input . applicationId , "idle" ) ;
149-
150- if ( application . serverId ) {
151- await startServiceRemote ( application . serverId , input . appName ) ;
152- } else {
153- await startService ( input . appName ) ;
154- }
155- await updateApplicationStatus ( input . applicationId , "done" ) ;
156- return true ;
157166 } ) ,
158167
159168 delete : protectedProcedure
0 commit comments