diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..b33eac6 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +node_modules +test/fixtures/non_existent.mbtiles diff --git a/lib/mbtiles.js b/lib/mbtiles.js index 7039fc5..4b7a54f 100644 --- a/lib/mbtiles.js +++ b/lib/mbtiles.js @@ -240,8 +240,8 @@ MBTiles.prototype.grid = function(x, y, z, callback) { ); }, function(err, row, rows) { + if ((!row || !row.grid) || (err && err.errno == 1)) return callback('Grid does not exist'); if (err) return callback(err); - if (!row || !row.grid) return callback('Grid does not exist'); try { var grid = zlib.inflate( @@ -253,10 +253,11 @@ MBTiles.prototype.grid = function(x, y, z, callback) { memo[r.key_name] = JSON.parse(r.key_json); return memo; }, {}); - callback(null, _(JSON.parse(grid)).extend({ data: data })); } catch (err) { - callback('Grid is invalid'); + return callback('Grid is invalid'); } + + callback(null, _(JSON.parse(grid)).extend({ data: data })); } ); }; diff --git a/test/fixtures/plain_1.mbtiles b/test/fixtures/plain_1.mbtiles index 8134d91..2ca8645 100644 Binary files a/test/fixtures/plain_1.mbtiles and b/test/fixtures/plain_1.mbtiles differ