Skip to content
This repository was archived by the owner on Nov 18, 2025. It is now read-only.

feat: properly decode error in fallback scenario, export FallbackServiceError type#866

Merged
alexander-fenster merged 3 commits intomasterfrom
fallback-errors
Jul 10, 2020
Merged

feat: properly decode error in fallback scenario, export FallbackServiceError type#866
alexander-fenster merged 3 commits intomasterfrom
fallback-errors

Conversation

@alexander-fenster
Copy link
Contributor

Fixes googleapis/google-cloud-node-core#395. Adapted a piece of error processing from @grpc/grpc-js to use in the fallback scenario.

@alexander-fenster alexander-fenster requested a review from a team as a code owner July 10, 2020 04:10
@googlebot googlebot added the cla: yes This human has signed the Contributor License Agreement. label Jul 10, 2020
@codecov
Copy link

codecov bot commented Jul 10, 2020

Codecov Report

Merging #866 into master will decrease coverage by 0.09%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     googleapis/gax-nodejs#866      +/-   ##
==========================================
- Coverage   88.72%   88.62%   -0.10%     
==========================================
  Files          40       40              
  Lines        6413     6429      +16     
  Branches      558      557       -1     
==========================================
+ Hits         5690     5698       +8     
- Misses        720      728       +8     
  Partials        3        3              
Impacted Files Coverage Δ
src/fallback.ts 77.64% <100.00%> (ø)
src/fallbackError.ts 91.48% <100.00%> (+1.74%) ⬆️
src/normalCalls/retries.ts 93.63% <0.00%> (-5.10%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 071f4e9...8dd43da. Read the comment docs.

// Adapted from https://github.com/grpc/grpc-node/blob/master/packages/grpc-js/src/call.ts#L79
callErrorFromStatus(status: DecodedRpcStatus): Error {
const message = `${status.code} ${Status[status.code]}: ${status.message}`;
delete status.message;
Copy link
Contributor

Choose a reason for hiding this comment

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

Why delete the message from the object?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In line 85, when I do new Error(message) it sets the message, but Object.assign will overwrite it from status.message. I can either delete it, or assign status.message = message (I can change it to the latter if you think it's more readable).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Changed this to more readable code.

Copy link
Contributor

Choose a reason for hiding this comment

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

Nope that's fine! Just poking.

callErrorFromStatus(status: DecodedRpcStatus): Error {
const message = `${status.code} ${Status[status.code]}: ${status.message}`;
delete status.message;
return Object.assign(new Error(message), status);
Copy link
Contributor

Choose a reason for hiding this comment

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

This line of code is confusing to me. It looks like you're smashing a DecodedRpcStatus onto an Error object, but not changing the type. Should we return a type here that reflects the properties you're returning?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, it's ServiceError from gRPC, I will import and use it here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Well no, I don't have any Metadata so I cannot use the type from gRPC but I'm now exporting my own (similar) type.

@alexander-fenster alexander-fenster changed the title fix: properly decode error in fallback scenario feat: properly decode error in fallback scenario, export FallbackServiceError type Jul 10, 2020
@alexander-fenster
Copy link
Contributor Author

This is ready for one more look @JustinBeckwith!

// Adapted from https://github.com/grpc/grpc-node/blob/master/packages/grpc-js/src/call.ts#L79
callErrorFromStatus(status: DecodedRpcStatus): Error {
const message = `${status.code} ${Status[status.code]}: ${status.message}`;
delete status.message;
Copy link
Contributor

Choose a reason for hiding this comment

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

Nope that's fine! Just poking.

@alexander-fenster alexander-fenster merged commit af15e53 into master Jul 10, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

cla: yes This human has signed the Contributor License Agreement.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Raise structured Errors instead of JSON strings in fallback client.

3 participants