Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is there a way to do matching error on client side ? #37

Open
fahmifan opened this issue Dec 11, 2021 · 2 comments
Open

Is there a way to do matching error on client side ? #37

fahmifan opened this issue Dec 11, 2021 · 2 comments

Comments

@fahmifan
Copy link

I'm trying oto and thanks it's made creating a client lib so easy. I wonder could oto create an error object for the client-side ? I imagine something like this

// definition.go
type ServiceError int

const (
	ErrInternal          ServiceError = 1000
	ErrPermissionDenined ServiceError = 1001
	ErrInvalidArgument   ServiceError = 1002
)

func (s ServiceError) Error() string {
	switch s {
	default: // ErrInternal
		return "internal"
        case ErrInvalidArgument:
                return "invalid_argument" 
	case ErrPermissionDenined:
		return "permission_denied"
	}
}
// client.js
const ErrInvalidArgument = new Error('permission_denied')
// index.js
try {
   res = await greeter.Greets(req)
} catch (err) {
   switch (err.message) {
    case greeter.ErrInvalidArgument:
        // do something
     case greeter.ErrPermissionDenined:
        // do something
     case greeter.ErrInternal:
        // do something
   }
}
@matryer
Copy link
Contributor

matryer commented Jan 25, 2022

Hey @fahmifan, I could see a reason to do this. You could modify the template and make this for yourself, but do you think the standard Oto template should also do this as well?

@fahmifan
Copy link
Author

@matryer That would be great really great, if OTO has this feature built in!
Unfortuantely i haven't got a chance to try implement the custom template my self, I'll try it if i got the chance

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

No branches or pull requests

2 participants