[ic] [interchange] Add better messages, support for application/json handling
Peter
peter at pajamian.dhs.org
Wed Dec 31 00:29:19 UTC 2014
On 12/31/2014 11:50 AM, David Christensen wrote:
> use strict;
>
> {
> - local $@;
> - eval {
> - require JSON;
> - };
> - unless ($@) {
> - $Has_JSON = 1;
> - }
> + local $@;
> + eval {
> + require JSON;
> + };
> + if ($@) {
> + ::logGlobal(
> + $@ =~ /^Can't locate JSON/ ?
> + 'No POST support for application/json without installing JSON module' :
> + "Error loading JSON module: $@"
> + );
> + }
> + else {
> + $Has_JSON = 1;
> + }
> }
One correction and a few suggestions...
$Has_JSON will puke because it's undeclared and we use strict. You want:
our $Has_JSON = 1;
You don't have to test for $@ if you put the our $Has_JSON = 1 in the
eval block like so:
our $Has_JSON;
eval {
require JSON;
$Has_JSON = 1;
};
if (!$Has_JSON) {
# ... error here (see below)?
}
The other thing is that if someone doesn't have JSON it's not really an
error and shouldn't be reported as such, unless they try to enable
UnpackJSON. I suggest that UnpackJSON should be *off* by default (to
maintain the status quo) and if it's attempted to be turned on with the
JSON module present *then* you record an error (and even crash the
catalog loading at that point).
Peter
More information about the interchange-users
mailing list