hi,

using Mojo::UserAgent 

$ mojo version
CORE
  Perl        (v5.24.1, linux)
  Mojolicious (7.27, Doughnut)

OPTIONAL
  EV 4.0+                 (n/a)
  IO::Socket::Socks 0.64+ (n/a)
  IO::Socket::SSL 1.94+   (2.038)
  Net::DNS::Native 0.15+  (n/a)

I am writing an api client to phpipam 
(https://phpipam.net/api/api_documentation/). This module is greatly 
simplifying my work, by the way, thanks!

I have a question regarding the error messages from the transactions. I 
have this code:

    my $tx = $ua->get( "$prot://$url$api/user/all/" => { 'token' => $token 
} );

    if ( $tx->success ) {
        $allusers = $tx->res->json('/data');
        return $allusers;
    }
    else {
        my $err = $tx->error;
        die "Could not get info on all users:  $err->{code} response -> 
$err->{message}";
   }

Which works perfectly fine until my api user identified by the token does 
not have the right permissions to the api. Then I get the right error code 
on $err->{code} but not the right message in $err->{message}, it seems.

When I use export MOJO_USERAGENT_DEBUG=1 and run my script, I see that the 
server returns something else:

-- Client <<< Server (http://192.168.5.22/phpipam/api/kkk/user/all/)
HTTP/1.1 503 Service Unavailable\x0d
Date: Tue, 07 Mar 2017 20:55:16 GMT\x0d
Server: Apache/2.4.6 (CentOS) PHP/5.4.16\x0d
X-Powered-By: PHP/5.4.16\x0d
Expires: Thu, 19 Nov 1981 08:52:00 GMT\x0d
Cache-Control: no-cache\x0d
Pragma: no-cache\x0d
Content-Length: 73\x0d
Connection: close\x0d
Content-Type: application/json; charset=utf-8\x0d
\x0d
{"code":503,"success":0,"message":"Invalid app permissions","time":0.017}
Could not get info on all users:  503 response -> Service Unavailable at 
lib/phpipam/API.pm line 116

So I would expect in $err->{message} "Invalid app permissions" instead of 
"Service Unavailable".

Am I doing something wrong?

TIA.

-- 
regards,
Natxo

-- 
You received this message because you are subscribed to the Google Groups 
"Mojolicious" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/mojolicious.
For more options, visit https://groups.google.com/d/optout.

Reply via email to