Merge pull request #1600 from deepak1556/protocol_error_patch
protocol: adding error job to log error with custom protocols
This commit is contained in:
commit
4a195e6283
5 changed files with 51 additions and 2 deletions
|
@ -105,6 +105,15 @@ class CustomProtocolRequestJob : public AdapterRequestJob {
|
||||||
base::Bind(&AdapterRequestJob::CreateFileJobAndStart,
|
base::Bind(&AdapterRequestJob::CreateFileJobAndStart,
|
||||||
GetWeakPtr(), path));
|
GetWeakPtr(), path));
|
||||||
return;
|
return;
|
||||||
|
} else if (name == "RequestErrorJob") {
|
||||||
|
// Default value net::ERR_NOT_IMPLEMENTED
|
||||||
|
int error = -11;
|
||||||
|
dict.Get("error", &error);
|
||||||
|
|
||||||
|
BrowserThread::PostTask(BrowserThread::IO, FROM_HERE,
|
||||||
|
base::Bind(&AdapterRequestJob::CreateErrorJobAndStart,
|
||||||
|
GetWeakPtr(), error));
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -30,4 +30,8 @@ protocol.RequestFileJob =
|
||||||
class RequestFileJob
|
class RequestFileJob
|
||||||
constructor: (@path) ->
|
constructor: (@path) ->
|
||||||
|
|
||||||
|
protocol.RequestErrorJob =
|
||||||
|
class RequestErrorJob
|
||||||
|
constructor: (@error) ->
|
||||||
|
|
||||||
module.exports = protocol
|
module.exports = protocol
|
||||||
|
|
|
@ -5,10 +5,10 @@
|
||||||
#include "atom/browser/net/adapter_request_job.h"
|
#include "atom/browser/net/adapter_request_job.h"
|
||||||
|
|
||||||
#include "base/threading/sequenced_worker_pool.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/url_request_string_job.h"
|
||||||
#include "atom/browser/net/asar/url_request_asar_job.h"
|
#include "atom/browser/net/asar/url_request_asar_job.h"
|
||||||
#include "atom/common/asar/asar_util.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 "content/public/browser/browser_thread.h"
|
||||||
#include "net/base/net_errors.h"
|
#include "net/base/net_errors.h"
|
||||||
#include "net/url_request/url_request_error_job.h"
|
#include "net/url_request/url_request_error_job.h"
|
||||||
|
|
|
@ -82,4 +82,25 @@ Create a request job which sends a string as response.
|
||||||
* `encoding` String - Default is `UTF-8`
|
* `encoding` String - Default is `UTF-8`
|
||||||
* `data` Buffer
|
* `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.
|
||||||
|
Default message is `net::ERR_NOT_IMPLEMENTED`. 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.
|
||||||
|
|
|
@ -58,6 +58,21 @@ describe 'protocol module', ->
|
||||||
assert false, 'Got error: ' + errorType + ' ' + error
|
assert false, 'Got error: ' + errorType + ' ' + error
|
||||||
protocol.unregisterProtocol 'atom-string-job'
|
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) ->
|
it 'returns RequestBufferJob should send buffer', (done) ->
|
||||||
data = new Buffer("hello")
|
data = new Buffer("hello")
|
||||||
job = new protocol.RequestBufferJob(data: data)
|
job = new protocol.RequestBufferJob(data: data)
|
||||||
|
|
Loading…
Reference in a new issue