oto
oto copied to clipboard
Is there a way to do matching error on client side ?
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
}
}
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?
@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