Tim van der Linden  committed a8aa5cd

Broken input port reader.

  • Participants
  • Parent commits c6f9051
  • Branches default

Comments (0)

Files changed (1)

File json-rpc-client.scm

      (sprintf "Cannot setup connection, the given ~S data is invalid. The ~S ~A"
 	      type type message))))
+(define (json-rpc-server-error code message)
+  (signal
+   (make-property-condition
+    'exn 'message
+     (sprintf "The JSON-RPC server returned an error. Errorcode: ~A, Native message: ~A"
+	      code message))))
 ; Helper for checking which type we have, did not want to use another dependency for that :)
 (define (get-type x)
     (cond ((input-port? x) "an input port")
 						      (if notification
 							  (cons 'id "1")))) ;ID is hardcoded - can't handle more then one request at a time...or can we?
-				  output)))))))
+				  output)
+		    (read-input input)))))))
 ; Helper for building a vector or alist from the parameters if present
 (define (build-params params)    
 (define (send-request request output)
     (write-json request output))
+; Read and parse the input sent back from the JSON-RPC server
+;; Error: The JSON-RPC server returnes an error object, so throw an error
+;; Response: The serer returns a response object, just pass it trough
+(define (read-input input)
+  (let ((input (read-json input)))
+    (if (alist-ref 'error input)
+	(json-rpc-server-error (alist-ref 'code (alist-ref 'error input)) 
+			       (alist-ref 'message (alist-ref 'error input)))
+	(display input))))