Currently when we get a validation error from the EM we have to parse the error as following:
err = h.controller.UninstallExtension(ctx, customerDB, extensionID, extensionVersion)
if err != nil {
emAPIError := emApiErrors.UnwrapAPIError(err)
if emAPIError.Status == http.StatusBadRequest {
return nil, exaerrors.NewBadRequestErrorF(err, "could not uninstall extension: %s", emAPIError.Message)
}
return nil, fmt.Errorf("Could not uninstall extension %w", err)
}
We cannot check for specific errors, only generic http.StatusBadRequest
It is harder to have our own messages to give to the user (in the future maybe also with translations)
That requires us to work with the specific error type apiError from the extension manager
This is fine but I think it could be made simpler, my bigger concerns are the previous points
Also I don't know if I'm missing something, but it doesn't make a lot of sense to call those errors API errors and put http status codes since it is never called as a http service? or is there a use-case for EM that is called via a url?
That limits us on the messages we can provide for the user and also our ability to maybe do our own internal error handling.
I propose we start exporting errors for specific issues that we can parse more easily, the end result would look like this:
err = h.controller.UninstallExtension(ctx, customerDB, extensionID, extensionVersion)
if err != nil {
if err == emErrors.ErrUninstallExistingInstances {
return nil, exaerrors.NewBadRequestErrorF(err, "could not uninstall extension because there are existing instances")
}
return nil, fmt.Errorf("Could not uninstall extension %w", err)
}
Currently when we get a validation error from the EM we have to parse the error as following:
http.StatusBadRequest
apiError
from the extension managerThat limits us on the messages we can provide for the user and also our ability to maybe do our own internal error handling.
I propose we start exporting errors for specific issues that we can parse more easily, the end result would look like this:
The errors would be declared in the extension manager, see example from the sql package: https://pkg.go.dev/database/sql#pkg-variables.