oklahomer / p5-Facebook-OpenGraph

Home Page:https://metacpan.org/release/Facebook-OpenGraph

Repository from Github https://github.comoklahomer/p5-Facebook-OpenGraphRepository from Github https://github.comoklahomer/p5-Facebook-OpenGraph

Handle newly added fields on error response

oklahomer opened this issue · comments

Handling Errors introduces some new fields along with the old ones. These should be treated properly when stringified form of error representation is constructed at below:

sub error_string {
my $self = shift;
# When error occurs, response should be given in a form of below:
#{
# "error": {
# "message": "Message describing the error",
# "type": "OAuthException",
# "code": 190 ,
# "error_subcode": 460
# }
#}
my $error = eval { $self->as_hashref->{error}; };
my $err_str = q{};
if ($@ || !$error) {
$err_str = $self->message;
}
else {
# sometimes error_subcode is not given
$err_str = sprintf(
'%s:%s %s:%s',
$error->{code},
$error->{error_subcode} || '-',
$error->{type},
$error->{message},
);
}
return $err_str;
}

NOTE: This was introduced in v2.1 as below:

In some cases (such as access token invalidation or expiry) the API now returns user-displayable error messages which describe the error and what the person may need to do to resolve it. These error messages will be returned in US English by default, but if you query the Graph API specifying the locale parameter (e.g. ?locale=es_ES) the string may be returned in the specified language.

The above description suggests these fields are not mandatory.