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

migrate database:get to new apiv2 client (with stream support!) #2781

Merged
merged 11 commits into from
Nov 6, 2020

Conversation

bkendall
Copy link
Contributor

@bkendall bkendall commented Nov 4, 2020

Description

  1. Adds streaming response support to the apiv2 client.
  2. Migrates the database:get command to the new apiv2 Client.

Scenarios Tested

database:get

  • with a valid path
  • with no auth (code change - tests the 4xx response path)
  • with an invalid path (returns null, same as head).
  • to a file

@google-cla google-cla bot added the cla: yes Manual indication that this has passed CLA. label Nov 4, 2020
@@ -238,6 +239,8 @@ export class Client {
let body: ResT;
if (options.responseType === "json") {
body = await res.json();
} else if (options.responseType === "stream") {
body = (res.body as unknown) as ResT;
Copy link
Member

Choose a reason for hiding this comment

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

I don't think src/responseToError.js will properly handle stream bodies. Mind fixing that (with a test)?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It... would JSON encode the stream object, which would just be weird. Until responseToError is TS'd, I would keep it as an exercise for the developer to not misuse the library (which we use in a correct way in this PR).

Copy link
Member

Choose a reason for hiding this comment

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

I'd push back on this one. Since resolveOnHTTPError is false by default, it's really easy to write and test for the happy cases but hit the error cases sometimes, leaving a cryptic error message. Yes I see your comments below -- but would it make sense to throw if resolveOnHTTPError is not set to true with streaming for now and recommend manually handling all errors? We can figure out a story if we find more common usages.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Alright - I'm throwing an error if (streaming && !resolvingOnHttpError), forcing the developer to have to set that and handle the error for now.

I'm open to future ideas on how to make responseToError better - especially when it comes to streaming!

src/commands/database-get.ts Outdated Show resolved Hide resolved
src/commands/database-get.ts Outdated Show resolved Hide resolved
src/test/apiv2.spec.ts Show resolved Hide resolved
@bkendall bkendall merged commit fea6258 into master Nov 6, 2020
@bkendall bkendall deleted the bk-db-get branch November 6, 2020 00:43
@bkendall bkendall added the cleanup: request PRs for removing the request module from the CLI label Nov 10, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla: yes Manual indication that this has passed CLA. cleanup: request PRs for removing the request module from the CLI
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants