-
Notifications
You must be signed in to change notification settings - Fork 87
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
fix: return Google Error when there is a missing required parameter #1291
Changes from 9 commits
c3fa981
13cb3ed
19e1618
1704500
606a5ae
33b65ce
5da7e40
ff333e8
bcd3616
753f17e
aac6f49
4f80ab4
414379a
76db51f
ea975fa
453f96b
2695c41
206b7c4
09374d3
7d5276e
42f07f8
9633068
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -61,6 +61,10 @@ export function encodeRequest( | |
rpc.parsedOptions, | ||
rpc.resolvedRequestType!.fields | ||
); | ||
if (transcoded instanceof GoogleError) { | ||
throw transcoded; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I finally got back to reviewing this. In line 68, you will throw There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hm, the only way I can think to fix this is how I had it before, namely:
I think changing it to try-catch causes the problem you're describing. |
||
} | ||
|
||
if (!transcoded) { | ||
throw new Error( | ||
`Cannot build HTTP request for ${JSON.stringify(json)}, method: ${ | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,6 +25,7 @@ import {hasWindowFetch, hasAbortController} from './featureDetection'; | |
import {AuthClient} from './fallback'; | ||
import {StreamArrayParser} from './streamArrayParser'; | ||
import {pipeline, PipelineSource} from 'stream'; | ||
import {GoogleError} from './googleError'; | ||
|
||
interface NodeFetchType { | ||
(url: RequestInfo, init?: RequestInit): Promise<Response>; | ||
|
@@ -37,7 +38,7 @@ export interface FallbackServiceStub { | |
options: {}, | ||
metadata: {}, | ||
callback: (err?: Error, response?: {} | undefined) => void | ||
) => StreamArrayParser | {cancel: () => void}; | ||
) => StreamArrayParser | {cancel: () => void} | Promise<GoogleError>; | ||
} | ||
|
||
export interface FetchParameters { | ||
|
@@ -91,14 +92,18 @@ export function generateServiceStub( | |
: new NodeAbortController(); | ||
const cancelSignal = cancelController.signal as AbortSignal; | ||
let cancelRequested = false; | ||
|
||
const fetchParameters = requestEncoder( | ||
rpc, | ||
protocol, | ||
servicePath, | ||
servicePort, | ||
request | ||
); | ||
let fetchParameters: FetchParameters; | ||
try { | ||
fetchParameters = requestEncoder( | ||
rpc, | ||
protocol, | ||
servicePath, | ||
servicePort, | ||
request | ||
); | ||
} catch (err) { | ||
return Promise.resolve(callback(err)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This seems to be the right place to catch it. I wonder if just doing There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I gave it a try, it didn't work! |
||
} | ||
const url = fetchParameters.url; | ||
const headers = fetchParameters.headers; | ||
for (const key of Object.keys(options)) { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here I think it's pretty much the same as putting the call to
transcode()
intotry ... catch
, then we won't need to change its return value. It may or may not be cleaner.