Skip to content

Return value #11

@djzort

Description

@djzort

I just wanted to discuss one thing that kind of bothers me with this base client library, which i have otherwise found extremely useful.

That is inconsistent behavior of return values. Please dont misunderstand that comment, as things are behaving as they are documented.

However, depending on the HTTP code the return value will either be a json string, undef or i will need to catch an exception. In the first two cases, i dont get to inspect the entire reply (easily) and in the third case i case i have to wrap everything in eval {} or try {} then look for $@ etc.


try {
   my $result = $obj->foo($etc);
}
catch {
  # do something if i get certain http codes, which may not be "errors"
};
unless ($result) {
  # handle no result being returned
}
if ($result....) {
   # actually do something with the result
}

For that reason, i would suggest instead that a WebService::Client::Response object be defined which is always returned regardless of the HTTP code, which would also have the http response headers, the json decode and the original response.

in which case you would always do something like:


my %dispatch =(
 404 => sub {},
 200 => sub {},
);

my $result = $obj->foo();

$dispatch{ $result->code }->();

Or a if/elseif/elseif/else chain, or a switch statement...

The return value may be an "error" in terms of http. but in a rest context its a meaningful return value. So having to catch it as a special case is inconsistent.

What do you think?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions