Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

protocol: adding error job to log error with custom protocols #1600

Merged
merged 2 commits into from
May 11, 2015
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
protocol: adding error job to log error with custom protocols
  • Loading branch information
deepak1556 committed May 11, 2015
commit 9ab53b0e4b49c2d2e8e6a67ed0d63d19825eaa6c
8 changes: 8 additions & 0 deletions atom/browser/api/atom_api_protocol.cc
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,14 @@ class CustomProtocolRequestJob : public AdapterRequestJob {
base::Bind(&AdapterRequestJob::CreateFileJobAndStart,
GetWeakPtr(), path));
return;
} else if (name == "RequestErrorJob") {
int error;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should have a default error here in case user didn't specify one.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah yeah, but what would be the default ?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe net::ERR_NOT_IMPLEMENTED.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

or net::ERR_TIMED_OUT ? will add the default value to the docs..

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

net::ERR_TIMED_OUT makes it look like a connection error.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cool, added net::ERR_NOT_IMPLEMENTED as default.

dict.Get("error", &error);

BrowserThread::PostTask(BrowserThread::IO, FROM_HERE,
base::Bind(&AdapterRequestJob::CreateErrorJobAndStart,
GetWeakPtr(), error));
return;
}
}

Expand Down
4 changes: 4 additions & 0 deletions atom/browser/api/lib/protocol.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,8 @@ protocol.RequestFileJob =
class RequestFileJob
constructor: (@path) ->

protocol.RequestErrorJob =
class RequestErrorJob
constructor: (@error) ->

module.exports = protocol
2 changes: 1 addition & 1 deletion atom/browser/net/adapter_request_job.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
#include "atom/browser/net/adapter_request_job.h"

#include "base/threading/sequenced_worker_pool.h"
#include "atom/browser/net/url_request_buffer_job.h"
#include "atom/browser/net/url_request_string_job.h"
#include "atom/browser/net/asar/url_request_asar_job.h"
#include "atom/common/asar/asar_util.h"
#include "atom/browser/net/url_request_buffer_job.h"
#include "content/public/browser/browser_thread.h"
#include "net/base/net_errors.h"
#include "net/url_request/url_request_error_job.h"
Expand Down
22 changes: 21 additions & 1 deletion docs/api/protocol.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,4 +82,24 @@ Create a request job which sends a string as response.
* `encoding` String - Default is `UTF-8`
* `data` Buffer

Create a request job which accepts a buffer and sends a string as response.
Create a request job which sends a buffer as response.

## Class: protocol.RequestErrorJob(code)

* `code` Integer

Create a request job which sets appropriate network error message to console.
Code should be in the following range.

* Ranges:
* 0- 99 System related errors
* 100-199 Connection related errors
* 200-299 Certificate errors
* 300-399 HTTP errors
* 400-499 Cache errors
* 500-599 ?
* 600-699 FTP errors
* 700-799 Certificate manager errors
* 800-899 DNS resolver errors

Check the [network error list](https://code.google.com/p/chromium/codesearch#chromium/src/net/base/net_error_list.h) for code and message relations.
15 changes: 15 additions & 0 deletions spec/api-protocol-spec.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,21 @@ describe 'protocol module', ->
assert false, 'Got error: ' + errorType + ' ' + error
protocol.unregisterProtocol 'atom-string-job'

it 'returns RequestErrorJob should send error', (done) ->
data = 'valar morghulis'
job = new protocol.RequestErrorJob(-6)
handler = remote.createFunctionWithReturnValue job
protocol.registerProtocol 'atom-error-job', handler

$.ajax
url: 'atom-error-job://fake-host'
success: (response) ->
assert false, 'should not reach here'
error: (xhr, errorType, error) ->
assert errorType, 'error'
protocol.unregisterProtocol 'atom-error-job'
done()

it 'returns RequestBufferJob should send buffer', (done) ->
data = new Buffer("hello")
job = new protocol.RequestBufferJob(data: data)
Expand Down