From 53c880832db1908eaa962a2de219fcbb9e902614 Mon Sep 17 00:00:00 2001 From: Andrew Bastin Date: Thu, 16 Jul 2020 12:41:23 -0400 Subject: [PATCH 1/3] Added proxy error handling code --- helpers/strategies/AxiosStrategy.js | 8 ++++++++ helpers/strategies/ExtensionStrategy.js | 12 +++++++++--- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/helpers/strategies/AxiosStrategy.js b/helpers/strategies/AxiosStrategy.js index 583cdcd19..ed84e988b 100644 --- a/helpers/strategies/AxiosStrategy.js +++ b/helpers/strategies/AxiosStrategy.js @@ -12,6 +12,10 @@ export const cancelRunningAxiosRequest = () => { const axiosWithProxy = async (req, { state }) => { try { + console.log({ + ...req, + wantsBinary: true, + }) const { data } = await axios.post( state.postwoman.settings.PROXY_URL || "https://postwoman.apollosoftware.xyz/", { @@ -23,6 +27,10 @@ const axiosWithProxy = async (req, { state }) => { } ) + if (!data.data.success) { + throw new Error(data.data.message || "Proxy Error") + } + if (data.isBinary) { data.data = decodeB64StringToArrayBuffer(data.data) } diff --git a/helpers/strategies/ExtensionStrategy.js b/helpers/strategies/ExtensionStrategy.js index c98204c35..b96737e28 100644 --- a/helpers/strategies/ExtensionStrategy.js +++ b/helpers/strategies/ExtensionStrategy.js @@ -25,11 +25,17 @@ const extensionWithProxy = async (req, { state }) => { }, }) - if (data.isBinary) { - data.data = decodeB64StringToArrayBuffer(data.data) + const parsedData = JSON.parse(data) + + if (!parsedData.data.success) { + throw new Error(parsedData.data.message || "Proxy Error") } - return data + if (parsedData.isBinary) { + parsedData.data = decodeB64StringToArrayBuffer(data.data) + } + + return parsedData } const extensionWithoutProxy = async (req, _store) => { From cbae718d25635d5ffd5bc7fabb7b4061a277d02e Mon Sep 17 00:00:00 2001 From: Andrew Bastin Date: Sun, 19 Jul 2020 17:37:53 -0400 Subject: [PATCH 2/3] Fixed Unexpected Token errors for GraphQL queries --- pages/graphql.vue | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pages/graphql.vue b/pages/graphql.vue index 33b9f8511..b7d6d8711 100644 --- a/pages/graphql.vue +++ b/pages/graphql.vue @@ -528,7 +528,7 @@ export default { const res = await sendNetworkRequest(reqOptions, this.$store) - const responseText = new TextDecoder("utf-8").decode(new Uint8Array(res.data)) + const responseText = new TextDecoder("utf-8").decode(res.data) this.response = JSON.stringify(JSON.parse(responseText), null, 2) @@ -629,7 +629,7 @@ export default { const data = await sendNetworkRequest(reqOptions, this.$store) - const response = new TextDecoder("utf-8").decode(new Uint8Array(data.data)) + const response = new TextDecoder("utf-8").decode(data.data) const introspectResponse = JSON.parse(response) const schema = gql.buildClientSchema(introspectResponse.data) From 4a1988dd23db4beb334f367f1a191efe3e1aa6a7 Mon Sep 17 00:00:00 2001 From: Andrew Bastin Date: Mon, 20 Jul 2020 23:47:22 -0400 Subject: [PATCH 3/3] Fixed crash on proxy error --- .../lenses/renderers/mixins/TextContentRendererMixin.js | 1 + helpers/strategies/AxiosStrategy.js | 4 ---- 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/components/lenses/renderers/mixins/TextContentRendererMixin.js b/components/lenses/renderers/mixins/TextContentRendererMixin.js index 30f31f517..805276498 100644 --- a/components/lenses/renderers/mixins/TextContentRendererMixin.js +++ b/components/lenses/renderers/mixins/TextContentRendererMixin.js @@ -4,6 +4,7 @@ export default { }, computed: { responseBodyText() { + if (typeof this.response.body === "string") return this.response.body return new TextDecoder("utf-8").decode(this.response.body) }, }, diff --git a/helpers/strategies/AxiosStrategy.js b/helpers/strategies/AxiosStrategy.js index ed84e988b..76180b72b 100644 --- a/helpers/strategies/AxiosStrategy.js +++ b/helpers/strategies/AxiosStrategy.js @@ -12,10 +12,6 @@ export const cancelRunningAxiosRequest = () => { const axiosWithProxy = async (req, { state }) => { try { - console.log({ - ...req, - wantsBinary: true, - }) const { data } = await axios.post( state.postwoman.settings.PROXY_URL || "https://postwoman.apollosoftware.xyz/", {