Merge pull request #125 from mapbox/failed-requests

Handle failed requests
This commit is contained in:
Mike Morris
2015-05-22 11:17:28 -04:00
4 changed files with 32 additions and 7 deletions

View File

@@ -204,10 +204,15 @@ void NodeMap::startRender(std::unique_ptr<NodeMap::RenderOptions> options) {
map.setLatLngZoom(mbgl::LatLng(options->latitude, options->longitude), options->zoom);
map.setBearing(options->bearing);
map.renderStill([this](std::unique_ptr<const mbgl::StillImage> result) {
assert(!image);
image = std::move(result);
uv_async_send(async);
map.renderStill([this](const std::exception_ptr eptr, std::unique_ptr<const mbgl::StillImage> result) {
if (eptr) {
error = std::move(eptr);
uv_async_send(async);
} else {
assert(!image);
image = std::move(result);
uv_async_send(async);
}
});
// Retain this object, otherwise it might get destructed before we are finished rendering the
@@ -238,7 +243,16 @@ void NodeMap::renderFinished() {
assert(!callback);
assert(!image);
if (img) {
if (error) {
// This must be empty to be prepared for the next render call.
error = nullptr;
assert(!error);
v8::Local<v8::Value> argv[] = {
NanError("Error rendering image")
};
cb->Call(1, argv);
} else if (img) {
auto result = NanNew<v8::Object>();
result->Set(NanNew("width"), NanNew(img->width));
result->Set(NanNew("height"), NanNew(img->height));

View File

@@ -50,6 +50,7 @@ private:
NodeFileSource &fs;
mbgl::Map map;
std::exception_ptr error;
std::unique_ptr<const mbgl::StillImage> image;
std::unique_ptr<NanCallback> callback;

View File

@@ -157,7 +157,6 @@ test('Map', function(t) {
fileSource.request = function(req) {
fs.readFile(path.join('test', req.url), function(err, data) {
req.respond(err, { data: data });
t.error(err);
});
};
fileSource.cancel = function() {};
@@ -199,6 +198,17 @@ test('Map', function(t) {
});
});
t.test('returns an error', function(t) {
setup(fileSource, function(map) {
map.load(style);
map.render({ zoom: 1 }, function(err, data) {
t.ok(err);
t.equal(err.message, 'Error rendering image');
t.end();
});
});
});
t.test('returns an image', function(t) {
setup(fileSource, function(map) {
map.load(style);

2
vendor/mbgl vendored