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

Streaming API error handling/reporting improvements #5141

Merged
merged 7 commits into from
Mar 24, 2020
Merged
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
Prev Previous commit
Next Next commit
Update docs.
changelog_begin

[JSON API - Experimental] Change Streaming API error format to match synchronous API:
``{"status": <400 | 401 | 404 | 500>, "errors": <JSON array of strings> }``. See #4521

changelog_end
  • Loading branch information
leo-da committed Mar 24, 2020
commit 3caa2bf5fa9b57ccd09898086073038513c70b24
31 changes: 31 additions & 0 deletions docs/source/json-api/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,8 @@ Successful response with a warning, HTTP status: 200 OK
"warnings": <JSON object>
}

.. _error-format:

Failure, HTTP status: 400 | 401 | 404 | 500
===========================================

Expand Down Expand Up @@ -1053,6 +1055,35 @@ Streaming API
Two subprotocols must be passed with every request, as described in
`Passing token with WebSockets <#passing-token-with-websockets>`__.

JavaScript/Node.js example demonstrating how to establish Streaming API connection.

.. code-block:: javascript

const WebSocket = require("ws")

console.log("Starting")

const tokenPrefix = "jwt.token."
const wsProtocol = "daml.ws.auth"
const jwt =
"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJodHRwczovL2RhbWwuY29tL2xlZGdlci1hcGkiOnsibGVkZ2VySWQiOiJNeUxlZGdlciIsImFwcGxpY2F0aW9uSWQiOiJmb29iYXIiLCJhY3RBcyI6WyJBbGljZSJdfX0.VdDI96mw5hrfM5ZNxLyetSVwcD7XtLT4dIdHIOa9lcU"
const subprotocol = `${tokenPrefix}${jwt},${wsProtocol}`

const ws = new WebSocket("ws://localhost:7575/v1/stream/query", [subprotocol])

ws.on("open", function open() {
ws.send(`{"templateIds": ["Iou:Iou"]}`)
Copy link
Contributor

Choose a reason for hiding this comment

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

I think you would typically write the JS object as an object and then encode it to JSON, yes?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

this is Javascript, no types who cares :) but yeah JSON.stringify should do the trick. I will change it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

    ws.on("open", function open() {
      ws.send(JSON.stringify({templateIds: ["Iou:Iou"]}))
    })

Copy link
Contributor

Choose a reason for hiding this comment

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

For sure :) you can at least catch dumb syntax typos like missing } or " this way.

})

ws.on("message", function incoming(data) {
console.log(data)
})

Error Reporting
===============

Errors reported as part of the standard ``on-message`` flow and formatted the same way as :ref:`synchronous API errors <error-format>`.

Contracts Query Stream
======================

Expand Down