Changeset 74


Ignore:
Timestamp:
Oct 18, 2006, 12:34:58 AM (13 years ago)
Author:
David Sheldon
Message:

Remove dependency on JSON and return error codes on error.

Fixes ticket:14

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/npemap.org.uk/cgi/get-postcodes.fcgi

    r61 r74  
    66use DBI;
    77use CGI::Fast qw/:standard -debug/;
    8 use JSON;
    98
    109use vars qw($dbname $dbhost $dbuser $dbpass);
     
    3534    # In case the database went away, make sure we have a connection
    3635    unless (setup_dbh()) {
    37         print_err('Error setting up database connection');
     36        print_internal_err('Error setting up database connection');
    3837        next REQUEST;
    3938    }
     
    6867    if (($cgi->param('maxeasting') - $cgi->param('mineasting') > $max_distance) or ($cgi->param('maxnorthing') - $cgi->param('minnorthing') > $max_distance)) {
    6968        print_err("The requested box is too large");
     69        next REQUEST;
    7070    }
    7171
     
    7979            print "addMarker('$$hash{postcode}', $$hash{easting}, $$hash{northing});\n";
    8080        }
    81         #print objToJson($hr) . "\n";
    8281    } else {
    83         print_err("Database error retrieving data");
     82        print_internal_err("Database error retrieving data");
    8483    }
    8584
     
    9291sub print_err($) {
    9392    my $err = shift;
    94     my $obj = { 'error' => $err };
    95     print "Content-type: text/x-json\n\n";
    96     print objToJson($obj) . "\n";
     93    print header("text/plain", "400 $err");
     94    print "Error: $err\n";
     95}
     96
     97sub print_internal_err($) {
     98    my $err = shift;
     99    print header("text/plain", "500 $err");
     100    print "Error: $err\n";
    97101}
    98102
Note: See TracChangeset for help on using the changeset viewer.