]> khamidou — GitHub mirrors - electron.git/commitdiff
protocol: adding error job to log error with custom protocols
authordeepak1556 <hop2deep@gmail.com>
Thu, 7 May 2015 07:42:35 +0000 (13:12 +0530)
committerdeepak1556 <hop2deep@gmail.com>
Mon, 11 May 2015 04:47:31 +0000 (10:17 +0530)
atom/browser/api/atom_api_protocol.cc
atom/browser/api/lib/protocol.coffee
atom/browser/net/adapter_request_job.cc
docs/api/protocol.md
spec/api-protocol-spec.coffee

index ecb9d416875aab16fa62d066e15cce80b104cf28..617a098adbc3ea0a8c70e232a9ef5bd0ffc4519e 100644 (file)
@@ -105,6 +105,14 @@ class CustomProtocolRequestJob : public AdapterRequestJob {
             base::Bind(&AdapterRequestJob::CreateFileJobAndStart,
                        GetWeakPtr(), path));
         return;
+      } else if (name == "RequestErrorJob") {
+        int error;
+        dict.Get("error", &error);
+
+        BrowserThread::PostTask(BrowserThread::IO, FROM_HERE,
+            base::Bind(&AdapterRequestJob::CreateErrorJobAndStart,
+                       GetWeakPtr(), error));
+        return;
       }
     }
 
index 6eae01462b424398e92d644564a4eae7d66153e8..c2db7800c08ddec757bb2cf8b296361ce0f0e33d 100644 (file)
@@ -30,4 +30,8 @@ protocol.RequestFileJob =
 class RequestFileJob
   constructor: (@path) ->
 
+protocol.RequestErrorJob =
+class RequestErrorJob
+  constructor: (@error) ->
+
 module.exports = protocol
index 86c82d7836cee33a2c7cbb683219e871bfb023a2..8b562bcbf248cf955ca7ab5f836c3e1ccfc35a88 100644 (file)
@@ -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"
index e554dbf5ebaa2ea6158eed3068e460f91fa552b6..bcc3352751f5b12cfada17e74dacf8157367924d 100644 (file)
@@ -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.
index 0b6c62c027548c130e2d9a038b61f609bd996725..69506156089f4b6def41a9db41966a4e600a885f 100644 (file)
@@ -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)