Skip to content
This repository was archived by the owner on May 30, 2024. It is now read-only.

Commit 57e947a

Browse files
author
Noah Hanjun Lee
authored
fix: update to display the error message. (#121)
* Fix to display the error message.
1 parent db1a4d0 commit 57e947a

File tree

7 files changed

+73
-41
lines changed

7 files changed

+73
-41
lines changed

internal/pkg/github/deployment.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,13 @@ func (g *Github) CreateRemoteDeployment(ctx context.Context, u *ent.User, r *ent
2626
})
2727
if res.StatusCode == http.StatusConflict {
2828
return nil, &vo.UnprocessibleDeploymentError{
29-
Err: err,
29+
Message: "There is a merge conflict or the commit's status checks failed",
30+
Err: err,
3031
}
3132
} else if res.StatusCode == http.StatusUnprocessableEntity {
3233
return nil, &vo.UnprocessibleDeploymentError{
33-
Err: err,
34+
Message: "Validation failed",
35+
Err: err,
3436
}
3537
}
3638
if err != nil {

internal/server/api/v1/repos/deployment.go

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,8 @@ func (r *Repo) CreateDeployment(c *gin.Context) {
8989

9090
cf, err := r.i.GetConfig(ctx, u, re)
9191
if vo.IsConfigNotFoundError(err) || vo.IsConfigParseError(err) {
92-
r.log.Warn("The config is invalid.", zap.Error(err))
93-
gb.ErrorResponse(c, http.StatusUnprocessableEntity, "The config is invalid.")
92+
r.log.Warn("The configuration is invalid.", zap.Error(err))
93+
gb.ErrorResponse(c, http.StatusUnprocessableEntity, "The configuration is invalid.")
9494
return
9595
} else if err != nil {
9696
r.log.Error("failed to get the configuration file.", zap.Error(err))
@@ -99,8 +99,8 @@ func (r *Repo) CreateDeployment(c *gin.Context) {
9999
}
100100

101101
if !cf.HasEnv(p.Env) {
102-
r.log.Warn("The env is not defined in the config.", zap.Error(err))
103-
gb.ErrorResponse(c, http.StatusUnprocessableEntity, "The env is not defined in the config.")
102+
r.log.Warn("The environment is not defined in the config.", zap.Error(err))
103+
gb.ErrorResponse(c, http.StatusUnprocessableEntity, "The environment is not defined in the config.")
104104
return
105105
}
106106

@@ -111,8 +111,8 @@ func (r *Repo) CreateDeployment(c *gin.Context) {
111111
}
112112

113113
if locked, err := r.i.HasLockOfRepoForEnv(ctx, re, p.Env); locked {
114-
r.log.Info("The env is locked.", zap.String("env", p.Env))
115-
gb.ErrorResponse(c, http.StatusUnprocessableEntity, "The env is locked. You should unlock the env before deploying.")
114+
r.log.Info("The environment is locked.", zap.String("env", p.Env))
115+
gb.ErrorResponse(c, http.StatusUnprocessableEntity, "The environment is locked.")
116116
return
117117
} else if err != nil {
118118
r.log.Error("It has failed to check the lock.", zap.Error(err))
@@ -141,7 +141,7 @@ func (r *Repo) CreateDeployment(c *gin.Context) {
141141
return
142142
} else if vo.IsUnprocessibleDeploymentError(err) {
143143
r.log.Warn("It is unprocessable entity.", zap.Error(err))
144-
gb.ErrorResponse(c, http.StatusUnprocessableEntity, "It is unprocessable entity.")
144+
gb.ErrorResponse(c, http.StatusUnprocessableEntity, "There is a merge conflict or the commit's status checks failed.")
145145
return
146146
} else if err != nil {
147147
r.log.Error("failed to deploy.", zap.Error(err))
@@ -194,8 +194,8 @@ func (r *Repo) UpdateDeployment(c *gin.Context) {
194194

195195
cf, err := r.i.GetConfig(ctx, u, re)
196196
if vo.IsConfigNotFoundError(err) || vo.IsConfigParseError(err) {
197-
r.log.Warn("The config is invalid.", zap.Error(err))
198-
gb.ErrorResponse(c, http.StatusUnprocessableEntity, "The config is invalid.")
197+
r.log.Warn("The configuration is invalid.", zap.Error(err))
198+
gb.ErrorResponse(c, http.StatusUnprocessableEntity, "The configuration is invalid.")
199199
return
200200
} else if err != nil {
201201
r.log.Error("failed to get the configuration file.", zap.Error(err))
@@ -204,8 +204,8 @@ func (r *Repo) UpdateDeployment(c *gin.Context) {
204204
}
205205

206206
if !cf.HasEnv(d.Env) {
207-
r.log.Warn("The env is not defined in the config.", zap.Error(err))
208-
gb.ErrorResponse(c, http.StatusUnprocessableEntity, "The env is not defined in the config.")
207+
r.log.Warn("The environment is not defined in the config.", zap.Error(err))
208+
gb.ErrorResponse(c, http.StatusUnprocessableEntity, "The environment is not defined in the config.")
209209
return
210210
}
211211

@@ -216,8 +216,8 @@ func (r *Repo) UpdateDeployment(c *gin.Context) {
216216
}
217217

218218
if locked, err := r.i.HasLockOfRepoForEnv(ctx, re, d.Env); locked {
219-
r.log.Info("The env is locked.", zap.String("env", d.Env))
220-
gb.ErrorResponse(c, http.StatusUnprocessableEntity, "The env is locked. You should unlock the env before deploying.")
219+
r.log.Info("The environment is locked.", zap.String("env", d.Env))
220+
gb.ErrorResponse(c, http.StatusUnprocessableEntity, "The environment is locked.")
221221
return
222222
} else if err != nil {
223223
r.log.Error("It has failed to check the lock.", zap.Error(err))
@@ -236,7 +236,7 @@ func (r *Repo) UpdateDeployment(c *gin.Context) {
236236

237237
if d, err = r.i.CreateRemoteDeployment(ctx, u, re, d, cf.GetEnv(d.Env)); vo.IsUnprocessibleDeploymentError(err) {
238238
r.log.Warn("It is unprocessible entity.", zap.Error(err))
239-
gb.ErrorResponse(c, http.StatusUnprocessableEntity, "It is unprocessible entity.")
239+
gb.ErrorResponse(c, http.StatusUnprocessableEntity, "There is a merge conflict or the commit's status checks failed.")
240240
return
241241
} else if err != nil {
242242
r.log.Error("It has failed to create the remote deployment.", zap.Error(err))
@@ -283,8 +283,8 @@ func (r *Repo) RollbackDeployment(c *gin.Context) {
283283

284284
cf, err := r.i.GetConfig(ctx, u, re)
285285
if vo.IsConfigNotFoundError(err) || vo.IsConfigParseError(err) {
286-
r.log.Warn("The config is invalid.", zap.Error(err))
287-
gb.ErrorResponse(c, http.StatusUnprocessableEntity, "The config is invalid.")
286+
r.log.Warn("The configuration is invalid.", zap.Error(err))
287+
gb.ErrorResponse(c, http.StatusUnprocessableEntity, "The configuration is invalid.")
288288
return
289289
} else if err != nil {
290290
r.log.Error("failed to get the configuration file.", zap.Error(err))
@@ -293,8 +293,8 @@ func (r *Repo) RollbackDeployment(c *gin.Context) {
293293
}
294294

295295
if !cf.HasEnv(d.Env) {
296-
r.log.Warn("The env is not defined in the config.", zap.Error(err))
297-
gb.ErrorResponse(c, http.StatusUnprocessableEntity, "The env is not defined in the config.")
296+
r.log.Warn("The environment is not defined in the configuration.", zap.Error(err))
297+
gb.ErrorResponse(c, http.StatusUnprocessableEntity, "The environment is not defined in the configuration.")
298298
return
299299
}
300300

@@ -305,8 +305,8 @@ func (r *Repo) RollbackDeployment(c *gin.Context) {
305305
}
306306

307307
if locked, err := r.i.HasLockOfRepoForEnv(ctx, re, d.Env); locked {
308-
r.log.Info("The env is locked.", zap.String("env", d.Env))
309-
gb.ErrorResponse(c, http.StatusUnprocessableEntity, "The env is locked. You should unlock the env before deploying.")
308+
r.log.Info("The environment is locked.", zap.String("env", d.Env))
309+
gb.ErrorResponse(c, http.StatusUnprocessableEntity, "The environment is locked.")
310310
return
311311
} else if err != nil {
312312
r.log.Error("It has failed to check the lock.", zap.Error(err))
@@ -337,7 +337,7 @@ func (r *Repo) RollbackDeployment(c *gin.Context) {
337337
return
338338
} else if vo.IsUnprocessibleDeploymentError(err) {
339339
r.log.Warn("It is unprocessable entity.", zap.Error(err))
340-
gb.ErrorResponse(c, http.StatusUnprocessableEntity, "It is unprocessable entity.")
340+
gb.ErrorResponse(c, http.StatusUnprocessableEntity, "There is a merge conflict or the commit's status checks failed.")
341341
return
342342
} else if err != nil {
343343
r.log.Error("It has failed to rollback.", zap.Error(err))

ui/src/App.less

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,12 @@
2525
}
2626
}
2727

28+
&-quote {
29+
padding: 0 0 0 .6em;
30+
border-left: 4px solid rgba(100,100,100,.2);
31+
opacity: .85;
32+
}
33+
2834
&-pending-icon {
2935
height: 7px;
3036
width: 7px;

ui/src/redux/deployment.tsx

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ export const deployToSCM = createAsyncThunk<Deployment, void, { state: {deployme
100100
async (_, { getState, rejectWithValue, requestId } ) => {
101101
const { repo, number, deploying, deployId } = getState().deployment
102102
if (!repo) {
103-
throw new Error("There is no repo.")
103+
throw new Error("The repo is undefined.")
104104
}
105105

106106
if (deploying !== RequestStatus.Pending || requestId !== deployId ) {
@@ -109,14 +109,18 @@ export const deployToSCM = createAsyncThunk<Deployment, void, { state: {deployme
109109

110110
try {
111111
const deployment = await updateDeploymentStatusCreated(repo.id, number)
112-
message.info(`Deploy successfully.`)
112+
message.info(`Deploy successfully.`, 3)
113113

114114
return deployment
115115
} catch(e) {
116116
if (e instanceof HttpForbiddenError) {
117117
message.error("Only write permission can deploy.", 3)
118118
} else if (e instanceof HttpUnprocessableEntityError) {
119-
message.error(<span>It is unprocesable entity. Discussions <a href="https://github.com/gitploy-io/gitploy/discussions/64">#64</a></span>, 3)
119+
const msg = <span>
120+
<span>It is unprocesable entity. Discussions <a href="https://github.com/gitploy-io/gitploy/discussions/64">#64</a></span><br/>
121+
<span className="gitploy-quote">{e.message}</span>
122+
</span>
123+
message.error(msg, 3)
120124
}
121125

122126
return rejectWithValue(e)

ui/src/redux/repoDeploy.tsx

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -254,10 +254,10 @@ export const deploy = createAsyncThunk<void, void, { state: {repoDeploy: RepoDep
254254
async (_ , { getState, rejectWithValue, requestId }) => {
255255
const { repo, env, type, branch, commit, tag, approvers, deploying, deployId } = getState().repoDeploy
256256
if (!repo) {
257-
throw new Error("The repo is not set.")
257+
throw new Error("The repo is undefined.")
258258
}
259259
if (!env) {
260-
throw new Error("The env is not set.")
260+
throw new Error("The env is undefined.")
261261
}
262262
if (deploying !== RequestStatus.Pending || requestId !== deployId ) {
263263
return
@@ -275,23 +275,31 @@ export const deploy = createAsyncThunk<void, void, { state: {repoDeploy: RepoDep
275275
throw new Error("The type should be one of them: commit, branch, and tag.")
276276
}
277277

278-
const msg = <span>
279-
It starts to deploy. <a href={`/${repo.namespace}/${repo.name}/deployments/${deployment.number}`}>#{deployment.number}</a>
280-
</span>
281278
if (!env.approval?.enabled) {
279+
const msg = <span>
280+
It starts to deploy. <a href={`/${repo.namespace}/${repo.name}/deployments/${deployment.number}`}>#{deployment.number}</a>
281+
</span>
282282
message.success(msg, 3)
283283
return
284284
}
285285

286286
approvers.forEach(async (approver) => {
287287
await createApproval(repo, deployment, approver)
288288
})
289+
290+
const msg = <span>
291+
It is waiting approvals. <a href={`/${repo.namespace}/${repo.name}/deployments/${deployment.number}`}>#{deployment.number}</a>
292+
</span>
289293
message.success(msg, 3)
290294
} catch(e) {
291295
if (e instanceof HttpForbiddenError) {
292296
message.error("Only write permission can deploy.", 3)
293297
} else if (e instanceof HttpUnprocessableEntityError) {
294-
message.error(<span>It is unprocesable entity. Discussions <a href="https://github.com/gitploy-io/gitploy/discussions/64">#64</a></span>, 3)
298+
const msg = <span>
299+
<span>It is unprocesable entity. Discussions <a href="https://github.com/gitploy-io/gitploy/discussions/64">#64</a></span><br/>
300+
<span className="gitploy-quote">{e.message}</span>
301+
</span>
302+
message.error(msg, 3)
295303
} else if (e instanceof HttpConflictError) {
296304
message.error("It has conflicted, please retry it.", 3)
297305
}

ui/src/redux/repoRollback.tsx

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -113,33 +113,44 @@ export const rollback = createAsyncThunk<void, void, { state: {repoRollback: Rep
113113
"repoRollback/deploy",
114114
async (_ , { getState, rejectWithValue, requestId }) => {
115115
const { repo, deployment, env, approvers, deployId, deploying } = getState().repoRollback
116-
if (!repo) throw new Error("The repo is not set.")
117-
if (!deployment) throw new Error("The deployment is null.")
118-
116+
if (!repo) {
117+
throw new Error("The repo is undefined.")
118+
}
119+
if (!deployment) {
120+
throw new Error("The deployment is undefined.")
121+
}
119122
if (!(deploying === RequestStatus.Pending && requestId === deployId )) {
120123
return
121124
}
122125

123126
try {
124127
const rollback = await rollbackDeployment(repo.id, deployment.number)
125128

126-
const msg = <span>
127-
It starts to rollback. <a href={`/${repo.namespace}/${repo.name}/deployments/${rollback.number}`}>#{rollback.number}</a>
128-
</span>
129129
if (!env?.approval?.enabled) {
130+
const msg = <span>
131+
It starts to rollback. <a href={`/${repo.namespace}/${repo.name}/deployments/${rollback.number}`}>#{rollback.number}</a>
132+
</span>
130133
message.success(msg, 3)
131134
return
132135
}
133136

134137
approvers.forEach(async (approver) => {
135138
await createApproval(repo, rollback, approver)
136139
})
140+
141+
const msg = <span>
142+
It is waiting approvals. <a href={`/${repo.namespace}/${repo.name}/deployments/${rollback.number}`}>#{rollback.number}</a>
143+
</span>
137144
message.success(msg, 3)
138145
} catch(e) {
139146
if (e instanceof HttpForbiddenError) {
140147
message.error("Only write permission can deploy.", 3)
141148
} else if (e instanceof HttpUnprocessableEntityError) {
142-
message.error(<span>It is unprocesable entity. Discussions <a href="https://github.com/gitploy-io/gitploy/discussions/64">#64</a></span>, 3)
149+
const msg = <span>
150+
<span>It is unprocesable entity. Discussions <a href="https://github.com/gitploy-io/gitploy/discussions/64">#64</a></span><br/>
151+
<span className="gitploy-quote">{e.message}</span>
152+
</span>
153+
message.error(msg, 3)
143154
} else if (e instanceof HttpConflictError) {
144155
message.error("It has conflicted, please retry it.", 3)
145156
}

vo/errors.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,11 +60,12 @@ func IsRefNotFoundError(err error) bool {
6060
}
6161

6262
type UnprocessibleDeploymentError struct {
63-
Err error
63+
Message string
64+
Err error
6465
}
6566

6667
func (e *UnprocessibleDeploymentError) Error() string {
67-
return e.Err.Error()
68+
return fmt.Sprintf("%s: %s", e.Message, e.Err)
6869
}
6970

7071
func IsUnprocessibleDeploymentError(err error) bool {

0 commit comments

Comments
 (0)