Skip to content

Commit

Permalink
Merge pull request #651 from lekaf974/chore/add-handle-google-error-s…
Browse files Browse the repository at this point in the history
…upport

chore: handle google errors with meshkit errors
  • Loading branch information
lekaf974 authored Jan 24, 2025
2 parents fc0e2ba + 2cbdbae commit 785a2df
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 3 deletions.
2 changes: 1 addition & 1 deletion helpers/component_info.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "meshkit",
"type": "library",
"next_error_code": 11279
"next_error_code": 11281
}
12 changes: 12 additions & 0 deletions utils/error.go
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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"})
}
4 changes: 2 additions & 2 deletions utils/google.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

0 comments on commit 785a2df

Please sign in to comment.