diff --git a/helpers/component_info.json b/helpers/component_info.json index 2de07edb..5f47c929 100644 --- a/helpers/component_info.json +++ b/helpers/component_info.json @@ -1,5 +1,5 @@ { "name": "meshkit", "type": "library", - "next_error_code": 11279 + "next_error_code": 11281 } \ No newline at end of file diff --git a/utils/error.go b/utils/error.go index 16cbd75b..6c03e06b 100644 --- a/utils/error.go +++ b/utils/error.go @@ -50,6 +50,10 @@ var ( ErrConvertToByteCode = "meshkit-11187" ErrOpenFileCode = "meshkit-11278" + + // Google Sheets Service Errors + ErrGoogleJwtInvalidCode = "meshkit-11279" + ErrGoogleSheetSRVCode = "meshkit-11280" ) var ( ErrExtractType = errors.New( @@ -241,3 +245,11 @@ func ErrCloseFile(err error) error { func ErrOpenFile(file string) error { return errors.New(ErrOpenFileCode, errors.Alert, []string{"unable to open file: ", file}, []string{}, []string{"The file does not exist in the location"}, []string{"Make sure to upload the correct file"}) } + +func ErrGoogleJwtInvalid(err error) error { + return errors.New(ErrGoogleJwtInvalidCode, errors.Alert, []string{"Invalid JWT credentials"}, []string{err.Error()}, []string{"Invalid JWT credentials"}, []string{"Make sure to provide valid JWT credentials"}) +} + +func ErrGoogleSheetSRV(err error) error { + return errors.New(ErrGoogleSheetSRVCode, errors.Alert, []string{"Error while creating Google Sheets Service"}, []string{err.Error()}, []string{"Issue happened with Google Sheets Service"}, []string{"Make you provide valid JWT credentials and Spreadsheet ID"}) +} diff --git a/utils/google.go b/utils/google.go index 72304196..024ca1b5 100644 --- a/utils/google.go +++ b/utils/google.go @@ -19,14 +19,14 @@ func NewSheetSRV(cred string) (*sheets.Service, error) { // authenticate and get configuration config, err := google.JWTConfigFromJSON(byt, "https://www.googleapis.com/auth/spreadsheets") if err != nil { - return nil, err + return nil, ErrGoogleJwtInvalid(err) } // create client with config and context client := config.Client(ctx) // create new service using client srv, err := sheets.NewService(ctx, option.WithHTTPClient(client)) if err != nil { - return nil, err + return nil, ErrGoogleSheetSRV(err) } return srv, nil }