Skip to content

Conversation

@jasikpark
Copy link
Contributor

This alters ToError() error to be Error() string to allow APIErrors to implement the Error interface.

@jasikpark jasikpark requested a review from johnmaguire May 6, 2025 15:57

// Check for any errors returned by the API
if err := r.Errors.ToError(); err != nil {
return nil, nil, nil, nil, &APIError{e: fmt.Errorf("unexpected error during enrollment: %v", err), ReqID: reqID}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like we're no longer capturing the request ID. We log this in mobile_nebula. I think we either need to come up with a solution to continue returning it in APIErrors, or maybe add it to every element in the []APIError (and add it to APIError), .... or just take the easier approach of returning a specific code here (ErrInvalidCode), which will also mean that callers don't all have to parse this themselves.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn't that lose information if the api server were to return an error other than "invalid code"?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How do you think we might be able to avoid that, and still return an explicit error for invalid codes here? How would the caller do it?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think the server ever returns invalid code along with an additional error. If it did, the caller might want to know that information. So I think what I would do is only return ErrInvalidCode if that's the only error. If there are multiple errors, leave the return as it was before.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

image

LGTM

@jasikpark jasikpark requested a review from johnmaguire May 7, 2025 19:01
client.go Outdated
return "invalid credentials"
}
var InvalidCredentialsError = fmt.Errorf("invalid credentials")
var InvalidCodeError = fmt.Errorf("invalid enrollment code")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i know you were just following the existing code, but these should be in the format ErrInvalidCredentials and ErrInvalidCode.

Since we'll have to update callers anyway (errors.As -> errors.Is for InvalidCredentialsError), I think we should fix the names now.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@jasikpark jasikpark requested a review from johnmaguire May 9, 2025 16:18
@jasikpark jasikpark force-pushed the change-api-errors-type branch from 93ce8c7 to d3a1c74 Compare May 9, 2025 16:21
@jasikpark jasikpark merged commit f2cf939 into main May 9, 2025
2 checks passed
@jasikpark jasikpark deleted the change-api-errors-type branch May 9, 2025 20:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants