jhthorsen / openapi-client

A client for talking to an Open API powered server
11 stars 17 forks source link

Return rejected Promise rather than croak. #24

Closed kiwiroy closed 4 years ago

kiwiroy commented 5 years ago

Would it be better to return a rejected Mojo::Promise rather than Carp::croak in call_p?

https://github.com/jhthorsen/openapi-client/blob/5b53b799a53712ecea77325aea144c19432550d4/lib/OpenAPI/Client.pm#L37-L41

Changing to this.

my $code = $self->can("${op}_p")
    or return Mojo::Promise->new->reject("[OpenAPI::Client] No such operationId");

Allows the usual

$api->call_p('incorrect?')->then(sub { ... }, sub { $error = shift; })->wait;
mohawk2 commented 5 years ago

This sounds to me like it would be far more idiomatic.

jhthorsen commented 4 years ago

Closing this in favor of #25.