diff options
author | Konstantin Käfer <mail@kkaefer.com> | 2016-01-11 11:10:39 +0100 |
---|---|---|
committer | Konstantin Käfer <mail@kkaefer.com> | 2016-01-14 14:35:02 +0100 |
commit | 4515bb00c0fd6c90050cf3befc4e848aaa7362c0 (patch) | |
tree | 839e6aeffb01fa204091085b820d39cb8be20397 /platform | |
parent | e195d86100e4896911a7b229b975725f65e68617 (diff) | |
download | qtlocation-mapboxgl-4515bb00c0fd6c90050cf3befc4e848aaa7362c0.tar.gz |
[node] extract the error message from the Error object
this avoids double "Error: Error: reason" messages
Diffstat (limited to 'platform')
-rw-r--r-- | platform/node/src/node_request.cpp | 18 |
1 files changed, 16 insertions, 2 deletions
diff --git a/platform/node/src/node_request.cpp b/platform/node/src/node_request.cpp index dd8f2336ca..8e03a3bc1d 100644 --- a/platform/node/src/node_request.cpp +++ b/platform/node/src/node_request.cpp @@ -52,10 +52,24 @@ NAN_METHOD(NodeRequest::Respond) { response.error = std::make_unique<Error>(Error::Reason::NotFound); } else if (info[0]->BooleanValue()) { + std::unique_ptr<Nan::Utf8String> message; + // Store the error string. - const Nan::Utf8String message { info[0]->ToString() }; + if (info[0]->IsObject()) { + auto err = info[0]->ToObject(); + if (Nan::Has(err, Nan::New("message").ToLocalChecked()).FromJust()) { + message = std::make_unique<Nan::Utf8String>( + Nan::Get(err, Nan::New("message").ToLocalChecked()) + .ToLocalChecked() + ->ToString()); + } + } + + if (!message) { + message = std::make_unique<Nan::Utf8String>(info[0]->ToString()); + } response.error = std::make_unique<Error>( - Error::Reason::Other, std::string{ *message, size_t(message.length()) }); + Error::Reason::Other, std::string{ **message, size_t(message->length()) }); } else if (info.Length() < 2 || !info[1]->IsObject()) { return Nan::ThrowTypeError("Second argument must be a response object"); |