-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Include the error message as well as error code in the error message #7762
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
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
2012c03
changes
fredzqm 6058e57
improve error message
fredzqm 87dda81
m
fredzqm 33df924
feedbacks
fredzqm f5d0e92
Merge branch 'master' into fz/exec-panel
fredzqm 7dfed30
m
fredzqm 3f599a6
Merge remote-tracking branch 'origin/master' into fz/exec-panel
fredzqm File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -13,14 +13,18 @@ import { EmulatorsController } from "../core/emulators"; | |
| import { dataConnectConfigs } from "../data-connect/config"; | ||
|
|
||
| import { firebaseRC } from "../core/config"; | ||
| import { executeGraphQL } from "../../../src/dataconnect/dataplaneClient"; | ||
| import { | ||
| dataconnectDataplaneClient, | ||
| executeGraphQL, | ||
| DATACONNECT_API_VERSION, | ||
| } from "../../../src/dataconnect/dataplaneClient"; | ||
| import { | ||
| ExecuteGraphqlRequest, | ||
| ExecuteGraphqlResponse, | ||
| ExecuteGraphqlResponseError, | ||
| Impersonation, | ||
| } from "../dataconnect/types"; | ||
| import { ClientResponse } from "../apiv2"; | ||
| import { Client, ClientResponse } from "../../../src/apiv2"; | ||
| import { InstanceType } from "./code-lens-provider"; | ||
| import { pluginLogger } from "../logger-wrapper"; | ||
| import { DataConnectToolkit } from "./toolkit"; | ||
|
|
@@ -78,47 +82,35 @@ export class DataConnectService { | |
| return response.text(); | ||
| } | ||
| private async handleProdResponse( | ||
| clientResponse: ClientResponse< | ||
| response: ClientResponse< | ||
| ExecuteGraphqlResponse | ExecuteGraphqlResponseError | ||
| >, | ||
| ): Promise<ExecutionResult> { | ||
| if (!(clientResponse.status >= 200 && clientResponse.status < 300)) { | ||
| if (!(response.status >= 200 && response.status < 300)) { | ||
| const errorResponse = | ||
| clientResponse as ClientResponse<ExecuteGraphqlResponseError>; | ||
| response as ClientResponse<ExecuteGraphqlResponseError>; | ||
| throw new DataConnectError( | ||
| `Request failed with status ${clientResponse.status}`, | ||
| errorResponse.body.error.message, | ||
| `Prod Request failed with status ${response.status}\nMessage ${errorResponse?.body?.error?.message}`, | ||
| ); | ||
| } | ||
| const successResponse = | ||
| clientResponse as ClientResponse<ExecuteGraphqlResponse>; | ||
| const successResponse = response as ClientResponse<ExecuteGraphqlResponse>; | ||
| return successResponse.body; | ||
| } | ||
|
|
||
| private async handleValidResponse( | ||
| response: Response, | ||
| private async handleEmulatorResponse( | ||
| response: ClientResponse< | ||
| ExecuteGraphqlResponse | ExecuteGraphqlResponseError | ||
| >, | ||
| ): Promise<ExecutionResult> { | ||
| const json = await this.decodeResponse(response, "application/json"); | ||
| assertExecutionResult(json); | ||
|
|
||
| return json; | ||
| } | ||
|
|
||
| private async handleInvalidResponse(response: Response): Promise<never> { | ||
| const cause = await this.decodeResponse(response); | ||
|
|
||
| throw new DataConnectError( | ||
| `Request failed with status ${response.status}`, | ||
|
Contributor
Author
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. It swallowed the error message here. |
||
| cause, | ||
| ); | ||
| } | ||
|
|
||
| private handleResponse(response: Response): Promise<ExecutionResult> { | ||
| if (response.status >= 200 && response.status < 300) { | ||
| return this.handleValidResponse(response); | ||
| if (!(response.status >= 200 && response.status < 300)) { | ||
| const errorResponse = | ||
| response as ClientResponse<ExecuteGraphqlResponseError>; | ||
| throw new DataConnectError( | ||
| `Emulator Request failed with status ${response.status}\nMessage ${errorResponse?.body?.error?.message}`, | ||
| ); | ||
| } | ||
|
|
||
| return this.handleInvalidResponse(response); | ||
| const successResponse = response as ClientResponse<ExecuteGraphqlResponse>; | ||
| return successResponse.body; | ||
| } | ||
|
|
||
| /** Encode a body while handling the fact that "variables" is raw JSON. | ||
|
|
@@ -243,23 +235,22 @@ export class DataConnectService { | |
| extensions: this._auth(), | ||
| }); | ||
| if (params.instance === InstanceType.PRODUCTION) { | ||
| const resp = await executeGraphQL(servicePath, prodBody); | ||
| const client = dataconnectDataplaneClient(); | ||
| const resp = await executeGraphQL(client, servicePath, prodBody); | ||
| return this.handleProdResponse(resp); | ||
| } else { | ||
| const resp = await fetch( | ||
| (await this.emulatorsController.getLocalEndpoint()) + | ||
| `/v1beta/${servicePath}:executeGraphql`, | ||
| { | ||
| method: "POST", | ||
| headers: { | ||
| Accept: "application/json", | ||
| "Content-Type": "application/json", | ||
| "x-mantle-admin": "all", | ||
| }, | ||
| body, | ||
| }, | ||
| ); | ||
| return this.handleResponse(resp); | ||
| const endpoint = this.emulatorsController.getLocalEndpoint(); | ||
| if (!endpoint) { | ||
| throw new DataConnectError( | ||
| `Emulator isn't running. Please start your emulator!`, | ||
| ); | ||
| } | ||
| const client = new Client({ | ||
| urlPrefix: endpoint, | ||
| apiVersion: DATACONNECT_API_VERSION, | ||
| }); | ||
| const resp = await executeGraphQL(client, servicePath, prodBody); | ||
| return this.handleEmulatorResponse(resp); | ||
| } | ||
| } | ||
|
|
||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
It swallowed the error message here.