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:
Gianluca Zuccarelli 2021-12-23 13:45:30 +00:00 committed by Sanne Raymaekers
parent daf24f8db3
commit cc981b887a
8 changed files with 142 additions and 68 deletions

View file

@ -10,6 +10,7 @@ import (
"github.com/osbuild/osbuild-composer/internal/upload/koji"
"github.com/osbuild/osbuild-composer/internal/worker"
"github.com/osbuild/osbuild-composer/internal/worker/clienterrors"
)
type KojiInitJobImpl struct {
@ -64,7 +65,7 @@ func (impl *KojiInitJobImpl) Run(job worker.Job) error {
var result worker.KojiInitJobResult
result.Token, result.BuildID, err = impl.kojiInit(args.Server, args.Name, args.Version, args.Release)
if err != nil {
result.KojiError = err.Error()
result.JobError = clienterrors.WorkerClientError(clienterrors.ErrorKojiInit, err.Error())
}
err = job.Update(&result)