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); 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() { void AutoUpdater::OnCheckingForUpdate() {
Emit("checking-for-update"); Emit("checking-for-update");
} }

View file

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

View file

@ -22,6 +22,9 @@ class Delegate {
// An error happened. // An error happened.
virtual void OnError(const std::string& error) {} 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 // Checking to see if there is an update
virtual void OnCheckingForUpdate() {} virtual void OnCheckingForUpdate() {}

View file

@ -116,7 +116,8 @@ void AutoUpdater::CheckForUpdates() {
[failureString appendString:@" "]; [failureString appendString:@" "];
[failureString appendString:error.localizedRecoverySuggestion]; [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) { if (g_update_available) {
[[g_updater relaunchToInstallUpdate] subscribeError:^(NSError* error) { [[g_updater relaunchToInstallUpdate] subscribeError:^(NSError* error) {
if (delegate) if (delegate)
delegate->OnError(base::SysNSStringToUTF8(error.localizedDescription)); delegate->OnError(base::SysNSStringToUTF8(error.localizedDescription),
error.code, base::SysNSStringToUTF8(error.domain));
}]; }];
} else { } else {
if (delegate) if (delegate)