osbuild-worker: implement structured errors
Implement the structured errors as defined by the worker client. Every error for each of the job types now returns a structured error with a reason and a specific error code. This will make it possible to differentiate between 4xx errors and 5xx errors. This commit refactors the way errors are implemented in the workers, but maintains backwards compatability in composer by checking for both kinds of errors.
This commit is contained in:
parent
daf24f8db3
commit
cc981b887a
8 changed files with 142 additions and 68 deletions
|
|
@ -216,8 +216,9 @@ func (h *apiHandlers) PostCompose(ctx echo.Context) error {
|
|||
}
|
||||
time.Sleep(500 * time.Millisecond)
|
||||
}
|
||||
if initResult.KojiError != "" {
|
||||
return echo.NewHTTPError(http.StatusBadRequest, fmt.Sprintf("Could not initialize build with koji: %v", initResult.KojiError))
|
||||
|
||||
if initResult.JobError != nil {
|
||||
return echo.NewHTTPError(http.StatusBadRequest, fmt.Sprintf("Could not initialize build with koji: %v", initResult.JobError.Reason))
|
||||
}
|
||||
|
||||
return ctx.JSON(http.StatusCreated, &api.ComposeResponse{
|
||||
|
|
@ -254,7 +255,7 @@ func composeStatusFromJobStatus(js *worker.JobStatus, initResult *worker.KojiIni
|
|||
return api.ComposeStatusValuePending
|
||||
}
|
||||
|
||||
if initResult.KojiError != "" {
|
||||
if initResult.JobError != nil {
|
||||
return api.ComposeStatusValueFailure
|
||||
}
|
||||
|
||||
|
|
@ -262,12 +263,12 @@ func composeStatusFromJobStatus(js *worker.JobStatus, initResult *worker.KojiIni
|
|||
if buildResult.OSBuildOutput != nil && !buildResult.OSBuildOutput.Success {
|
||||
return api.ComposeStatusValueFailure
|
||||
}
|
||||
if buildResult.KojiError != "" {
|
||||
if buildResult.JobError != nil {
|
||||
return api.ComposeStatusValueFailure
|
||||
}
|
||||
}
|
||||
|
||||
if result.KojiError != "" {
|
||||
if result.JobError != nil {
|
||||
return api.ComposeStatusValueFailure
|
||||
}
|
||||
|
||||
|
|
@ -279,7 +280,7 @@ func imageStatusFromJobStatus(js *worker.JobStatus, initResult *worker.KojiInitJ
|
|||
return api.ImageStatusValueFailure
|
||||
}
|
||||
|
||||
if initResult.KojiError != "" {
|
||||
if initResult.JobError != nil {
|
||||
return api.ImageStatusValueFailure
|
||||
}
|
||||
|
||||
|
|
@ -291,7 +292,7 @@ func imageStatusFromJobStatus(js *worker.JobStatus, initResult *worker.KojiInitJ
|
|||
return api.ImageStatusValueBuilding
|
||||
}
|
||||
|
||||
if buildResult.OSBuildOutput != nil && buildResult.OSBuildOutput.Success && buildResult.KojiError == "" {
|
||||
if buildResult.OSBuildOutput != nil && buildResult.OSBuildOutput.Success && buildResult.JobError == nil {
|
||||
return api.ImageStatusValueSuccess
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue