Enable return error for arbitray request job
This commit is contained in:
parent
ee51e37db7
commit
337460cdc2
2 changed files with 20 additions and 5 deletions
|
@ -110,6 +110,18 @@ void AskForOptions(v8::Isolate* isolate,
|
||||||
handler.Run(request, wrapped_callback.ToLocalChecked());
|
handler.Run(request, wrapped_callback.ToLocalChecked());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool IsErrorOptions(base::Value* value, int* error) {
|
||||||
|
if (value->IsType(base::Value::TYPE_DICTIONARY)) {
|
||||||
|
base::DictionaryValue* dict = static_cast<base::DictionaryValue*>(value);
|
||||||
|
if (dict->GetInteger("error", error))
|
||||||
|
return true;
|
||||||
|
} else if (value->IsType(base::Value::TYPE_INTEGER)) {
|
||||||
|
if (value->GetAsInteger(error))
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace internal
|
} // namespace internal
|
||||||
|
|
||||||
} // namespace atom
|
} // namespace atom
|
||||||
|
|
|
@ -29,6 +29,9 @@ void AskForOptions(v8::Isolate* isolate,
|
||||||
net::URLRequest* request,
|
net::URLRequest* request,
|
||||||
const ResponseCallback& callback);
|
const ResponseCallback& callback);
|
||||||
|
|
||||||
|
// Test whether the |options| means an error.
|
||||||
|
bool IsErrorOptions(base::Value* value, int* error);
|
||||||
|
|
||||||
} // namespace internal
|
} // namespace internal
|
||||||
|
|
||||||
template<typename RequestJob>
|
template<typename RequestJob>
|
||||||
|
@ -63,13 +66,13 @@ class JsAsker : public RequestJob {
|
||||||
|
|
||||||
// Called when the JS handler has sent the response, we need to decide whether
|
// Called when the JS handler has sent the response, we need to decide whether
|
||||||
// to start, or fail the job.
|
// to start, or fail the job.
|
||||||
void OnResponse(bool success, scoped_ptr<base::Value> options) {
|
void OnResponse(bool success, scoped_ptr<base::Value> value) {
|
||||||
if (success && options) {
|
int error = net::ERR_NOT_IMPLEMENTED;
|
||||||
StartAsync(options.Pass());
|
if (success && value && !internal::IsErrorOptions(value.get(), &error)) {
|
||||||
|
StartAsync(value.Pass());
|
||||||
} else {
|
} else {
|
||||||
RequestJob::NotifyStartError(
|
RequestJob::NotifyStartError(
|
||||||
net::URLRequestStatus(net::URLRequestStatus::FAILED,
|
net::URLRequestStatus(net::URLRequestStatus::FAILED, error));
|
||||||
net::ERR_NOT_IMPLEMENTED));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue