googleinterns / cloud-operations-api-mock

Apache License 2.0
5 stars 2 forks source link

Refactor ErrMissingField and similar error handling #15

Closed mabdi3 closed 4 years ago

mabdi3 commented 4 years ago

~Following https://blog.golang.org/go1.13-errors, we want to refactor ErrMissingField as a struct, where we override the Error(), like so:~

func (err *MissingFieldError) Error() string {
    return fmt.Sprintf("request is missing required fields: %v",
        strings.Join(err.missingFields, ", "))
}

EDIT: ~Instead, we're going to try and handle errors more gracefully.~ We're just going to keep the error handling the way it is now, and hide it to users of the api. See here. In addition, we can replace the string checking for determining errors with ID checking instead since string comparisons are very brittle. Issue linked here.

the-ericwang35 commented 4 years ago

Closing this since we need to keep our errors as statuses for gRPC (see here, and we're hiding them from the users now after https://github.com/googleinterns/cloud-operations-api-mock/pull/19. We should still figure out a better way of testing these errors (that's the only reason we're exporting the statuses anyways), which can be done in https://github.com/googleinterns/cloud-operations-api-mock/issues/22