From b4aa7ff32ec86c00f4d9ed36798ca206d77d3ae5 Mon Sep 17 00:00:00 2001 From: Samarth Deyagond Date: Wed, 14 Apr 2021 10:42:02 +0530 Subject: [PATCH] Updated the error codes --- pkg/vsphere/machine_server.go | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/pkg/vsphere/machine_server.go b/pkg/vsphere/machine_server.go index 157382f5..412d231f 100644 --- a/pkg/vsphere/machine_server.go +++ b/pkg/vsphere/machine_server.go @@ -68,7 +68,8 @@ func (ms *MachinePlugin) CreateMachine(ctx context.Context, req *driver.CreateMa // check if the machineClass is of the supported provider if req.MachineClass.Provider != Providervsphere { - return nil, fmt.Errorf("Requested provider is '%s'. We support only '%s'", req.MachineClass.Provider, Providervsphere) + err := fmt.Errorf("Requested provider is '%s'. We support only '%s'", req.MachineClass.Provider, Providervsphere) + return nil, status.Error(codes.InvalidArgument, err.Error()) } providerSpec, err := decodeProviderSpecAndSecret(req.MachineClass, req.Secret) @@ -110,7 +111,8 @@ func (ms *MachinePlugin) DeleteMachine(ctx context.Context, req *driver.DeleteMa // check if the machineClass is of the supported provider if req.MachineClass.Provider != Providervsphere { - return nil, fmt.Errorf("Requested provider is '%s'. We support only '%s'", req.MachineClass.Provider, Providervsphere) + err := fmt.Errorf("Requested provider is '%s'. We support only '%s'", req.MachineClass.Provider, Providervsphere) + return nil, status.Error(codes.InvalidArgument, err.Error()) } providerSpec, err := decodeProviderSpecAndSecret(req.MachineClass, req.Secret) @@ -150,7 +152,8 @@ func (ms *MachinePlugin) GetMachineStatus(ctx context.Context, req *driver.GetMa // check if the machineClass is of the supported provider if req.MachineClass.Provider != Providervsphere { - return nil, fmt.Errorf("Requested provider is '%s'. We support only '%s'", req.MachineClass.Provider, Providervsphere) + err := fmt.Errorf("Requested provider is '%s'. We support only '%s'", req.MachineClass.Provider, Providervsphere) + return nil, status.Error(codes.InvalidArgument, err.Error()) } providerSpec, err := decodeProviderSpecAndSecret(req.MachineClass, req.Secret) @@ -192,7 +195,8 @@ func (ms *MachinePlugin) ListMachines(ctx context.Context, req *driver.ListMachi // check if the machineClass is of the supported provider if req.MachineClass.Provider != Providervsphere { - return nil, fmt.Errorf("Requested provider is '%s'. We support only '%s'", req.MachineClass.Provider, Providervsphere) + err := fmt.Errorf("Requested provider is '%s'. We support only '%s'", req.MachineClass.Provider, Providervsphere) + return nil, status.Error(codes.InvalidArgument, err.Error()) } providerSpec, err := decodeProviderSpecAndSecret(req.MachineClass, req.Secret)