Skip to content

Commit

Permalink
Add operation serviceCallFailure to communicate failure of calling …
Browse files Browse the repository at this point in the history
…a service (#733)

### Changelog
Add operation `serviceCallFailure` to communicate failure of calling a
service

### Description
The current spec lacks a way to communicate the failure of calling a
service. This PR changes that by adding a new operation which serves
that purpose.

---------

Co-authored-by: Jacob Bandes-Storch <[email protected]>
  • Loading branch information
achim-k and jtbandes authored Apr 24, 2024
1 parent ba536c3 commit aa7d846
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 2 deletions.
25 changes: 25 additions & 0 deletions docs/spec.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
- [Service Call Response](#service-call-response) (binary)
- [Connection Graph Update](#connection-graph-update) (json)
- [Fetch Asset Response](#fetch-asset-response) (binary)
- [Service Call Failure](#service-call-failure) (json)

### Sent by client

Expand Down Expand Up @@ -297,6 +298,29 @@ Informs the client about updates to the connection graph. This is only sent to c
}
```

### Service Call Failure

Informs the client about failure to [call a service](#service-call-request).
Only supported if the server previously declared that it has the `services` [capability](#server-info).

#### Fields

- `op`: string `"serviceCallFailure"`
- `serviceId`: number
- `callId`: number
- `message`: string

#### Example

```json
{
"op": "serviceCallFailure",
"serviceId": 1,
"callId": 1,
"message": "Service does not exist",
}
```

### Subscribe

- Requests that the server start streaming messages on a given topic (or topics) to the client.
Expand Down Expand Up @@ -574,6 +598,7 @@ All integer types explicitly specified (uint32, uint64, etc.) in this section ar
### Service Call Response

- Provides the response to a previous [service call](#service-call-request).
- If the service call failed, a [service call failure](#service-call-failure) response will be sent instead.
- Only supported if the server previously declared the `services` [capability](#server-info).

| Bytes | Type | Description |
Expand Down
2 changes: 1 addition & 1 deletion python/setup.cfg
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[metadata]
name = foxglove-websocket
version = 0.1.2
version = 0.1.3
description = Foxglove WebSocket server
long_description = file: README.md
long_description_content_type = text/markdown
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,11 @@ async function main(url: string) {

client.close();
});

client.on("serviceCallFailure", (event) => {
console.error(`Failed to call service ${event.serviceId}: ${event.message}`);
client.close();
});
}

export default new Command("service-client")
Expand Down
6 changes: 6 additions & 0 deletions typescript/ws-protocol/src/FoxgloveClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import {
ParameterValues,
ServerMessage,
Service,
ServiceCallFailure,
ServiceCallPayload,
ServiceCallResponse,
ServiceId,
Expand All @@ -41,6 +42,7 @@ type EventTypes = {
serviceCallResponse: (event: ServiceCallResponse) => void;
connectionGraphUpdate: (event: ConnectionGraphUpdate) => void;
fetchAssetResponse: (event: FetchAssetResponse) => void;
serviceCallFailure: (event: ServiceCallFailure) => void;
};

const textEncoder = new TextEncoder();
Expand Down Expand Up @@ -132,6 +134,10 @@ export default class FoxgloveClient {
this.#emitter.emit("connectionGraphUpdate", message);
return;

case "serviceCallFailure":
this.#emitter.emit("serviceCallFailure", message);
return;

case BinaryOpcode.MESSAGE_DATA:
this.#emitter.emit("message", message);
return;
Expand Down
9 changes: 8 additions & 1 deletion typescript/ws-protocol/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,12 @@ export type FetchAssetErrorResponse = {
error: string;
};
export type FetchAssetResponse = FetchAssetSuccessResponse | FetchAssetErrorResponse;
export type ServiceCallFailure = {
op: "serviceCallFailure";
serviceId: number;
callId: number;
message: string;
};
export type ClientPublish = {
channel: ClientChannel;
data: DataView;
Expand Down Expand Up @@ -264,7 +270,8 @@ export type ServerMessage =
| ServiceCallResponse
| ParameterValues
| ConnectionGraphUpdate
| FetchAssetResponse;
| FetchAssetResponse
| ServiceCallFailure;

/**
* Abstraction that supports both browser and Node WebSocket clients.
Expand Down

0 comments on commit aa7d846

Please sign in to comment.