Merge pull request #10125 from electron/autoupdater_prefix_error_string

prefix autoupdater error with statuscode and domain
This commit is contained in:
Shelley Vohr 2017-07-26 23:49:08 -07:00 committed by GitHub
commit 768e8388d2
4 changed files with 27 additions and 3 deletions

View file

@ -57,6 +57,23 @@ void AutoUpdater::OnError(const std::string& message) {
message);
}
void AutoUpdater::OnError(const std::string& message,
const int code, const std::string& domain) {
v8::Locker locker(isolate());
v8::HandleScope handle_scope(isolate());
auto error = v8::Exception::Error(mate::StringToV8(isolate(), message));
auto errorObject = error->ToObject(
isolate()->GetCurrentContext()).ToLocalChecked();
// add two new params for better error handling
errorObject->Set(mate::StringToV8(isolate(), "code"),
v8::Integer::New(isolate(), code));
errorObject->Set(mate::StringToV8(isolate(), "domain"),
mate::StringToV8(isolate(), domain));
mate::EmitEvent(isolate(), GetWrapper(), "error", errorObject, message);
}
void AutoUpdater::OnCheckingForUpdate() {
Emit("checking-for-update");
}

View file

@ -32,6 +32,8 @@ class AutoUpdater : public mate::EventEmitter<AutoUpdater>,
// Delegate implementations.
void OnError(const std::string& error) override;
void OnError(const std::string& message, const int code,
const std::string& domain);
void OnCheckingForUpdate() override;
void OnUpdateAvailable() override;
void OnUpdateNotAvailable() override;

View file

@ -22,6 +22,9 @@ class Delegate {
// An error happened.
virtual void OnError(const std::string& error) {}
virtual void OnError(const std::string& error, const int code,
const std::string& domain) {}
// Checking to see if there is an update
virtual void OnCheckingForUpdate() {}

View file

@ -104,7 +104,7 @@ void AutoUpdater::CheckForUpdates() {
delegate->OnUpdateNotAvailable();
}
} error:^(NSError *error) {
NSMutableString* failureString =
NSMutableString *failureString =
[NSMutableString stringWithString:error.localizedDescription];
if (error.localizedFailureReason) {
[failureString appendString:@": "];
@ -116,7 +116,8 @@ void AutoUpdater::CheckForUpdates() {
[failureString appendString:@" "];
[failureString appendString:error.localizedRecoverySuggestion];
}
delegate->OnError(base::SysNSStringToUTF8(failureString));
delegate->OnError(base::SysNSStringToUTF8(failureString), error.code,
base::SysNSStringToUTF8(error.domain));
}];
}
@ -125,7 +126,8 @@ void AutoUpdater::QuitAndInstall() {
if (g_update_available) {
[[g_updater relaunchToInstallUpdate] subscribeError:^(NSError* error) {
if (delegate)
delegate->OnError(base::SysNSStringToUTF8(error.localizedDescription));
delegate->OnError(base::SysNSStringToUTF8(error.localizedDescription),
error.code, base::SysNSStringToUTF8(error.domain));
}];
} else {
if (delegate)