Skip to content

Commit 00ece36

Browse files
committed
improved handling of api response based on charset
1 parent ca378a7 commit 00ece36

File tree

7 files changed

+57
-44
lines changed

7 files changed

+57
-44
lines changed

dist/rapidoc-min.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/rapidoc-min.js.gz

24 Bytes
Binary file not shown.

dist/report.html

Lines changed: 2 additions & 2 deletions
Large diffs are not rendered by default.

docs/rapidoc-min.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@
4444
"lint-fix": "./node_modules/eslint/bin/eslint.js --fix ./src/**"
4545
},
4646
"devDependencies": {
47-
"@babel/core": "^7.12.13",
48-
"@babel/preset-env": "^7.12.13",
47+
"@babel/core": "^7.12.16",
48+
"@babel/preset-env": "^7.12.16",
4949
"babel-eslint": "^10.1.0",
5050
"babel-loader": "^8.2.2",
5151
"babel-plugin-template-html-minifier": "^4.1.0",

src/components/api-request.js

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1212,10 +1212,18 @@ export default class ApiRequest extends LitElement {
12121212
if (contentType) {
12131213
if (contentType.includes('json')) {
12141214
if ((/charset=[^"']+/).test(contentType)) {
1215-
const enc = contentType.split('charset=')[1];
1215+
const encoding = contentType.split('charset=')[1];
12161216
const buffer = await tryResp.arrayBuffer();
1217-
respJson = new TextDecoder(enc).decode(buffer);
1218-
me.responseText = JSON.stringify(respJson, null, 2);
1217+
try {
1218+
respText = new TextDecoder(encoding).decode(buffer);
1219+
} catch {
1220+
respText = new TextDecoder('utf-8').decode(buffer);
1221+
}
1222+
try {
1223+
me.responseText = JSON.stringify(JSON.parse(respText), null, 2);
1224+
} catch {
1225+
me.responseText = respText;
1226+
}
12191227
} else {
12201228
respJson = await tryResp.json();
12211229
me.responseText = JSON.stringify(respJson, null, 2);

yarn.lock

Lines changed: 38 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -28,16 +28,16 @@
2828
resolved "https://registry.yarnpkg.com/@babel/compat-data/-/compat-data-7.12.13.tgz#27e19e0ed3726ccf54067ced4109501765e7e2e8"
2929
integrity sha512-U/hshG5R+SIoW7HVWIdmy1cB7s3ki+r3FpyEZiCgpi4tFgPnX/vynY80ZGSASOIrUM6O7VxOgCZgdt7h97bUGg==
3030

31-
"@babel/core@^7.12.13":
32-
version "7.12.13"
33-
resolved "https://registry.yarnpkg.com/@babel/core/-/core-7.12.13.tgz#b73a87a3a3e7d142a66248bf6ad88b9ceb093425"
34-
integrity sha512-BQKE9kXkPlXHPeqissfxo0lySWJcYdEP0hdtJOH/iJfDdhOCcgtNCjftCJg3qqauB4h+lz2N6ixM++b9DN1Tcw==
31+
"@babel/core@^7.12.16":
32+
version "7.12.16"
33+
resolved "https://registry.yarnpkg.com/@babel/core/-/core-7.12.16.tgz#8c6ba456b23b680a6493ddcfcd9d3c3ad51cab7c"
34+
integrity sha512-t/hHIB504wWceOeaOoONOhu+gX+hpjfeN6YRBT209X/4sibZQfSF1I0HFRRlBe97UZZosGx5XwUg1ZgNbelmNw==
3535
dependencies:
3636
"@babel/code-frame" "^7.12.13"
37-
"@babel/generator" "^7.12.13"
37+
"@babel/generator" "^7.12.15"
3838
"@babel/helper-module-transforms" "^7.12.13"
3939
"@babel/helpers" "^7.12.13"
40-
"@babel/parser" "^7.12.13"
40+
"@babel/parser" "^7.12.16"
4141
"@babel/template" "^7.12.13"
4242
"@babel/traverse" "^7.12.13"
4343
"@babel/types" "^7.12.13"
@@ -49,7 +49,7 @@
4949
semver "^5.4.1"
5050
source-map "^0.5.0"
5151

52-
"@babel/generator@^7.12.13":
52+
"@babel/generator@^7.12.13", "@babel/generator@^7.12.15":
5353
version "7.12.15"
5454
resolved "https://registry.yarnpkg.com/@babel/generator/-/generator-7.12.15.tgz#4617b5d0b25cc572474cc1aafee1edeaf9b5368f"
5555
integrity sha512-6F2xHxBiFXWNSGb7vyCUTBF8RCLY66rS0zEPcP8t/nQyXjha5EuK4z7H5o7fWG8B4M7y6mqVWq1J+1PuwRhecQ==
@@ -90,13 +90,13 @@
9090
"@babel/helper-explode-assignable-expression" "^7.12.13"
9191
"@babel/types" "^7.12.13"
9292

93-
"@babel/helper-compilation-targets@^7.12.13":
94-
version "7.12.13"
95-
resolved "https://registry.yarnpkg.com/@babel/helper-compilation-targets/-/helper-compilation-targets-7.12.13.tgz#d689cdef88810aa74e15a7a94186f26a3d773c98"
96-
integrity sha512-dXof20y/6wB5HnLOGyLh/gobsMvDNoekcC+8MCV2iaTd5JemhFkPD73QB+tK3iFC9P0xJC73B6MvKkyUfS9cCw==
93+
"@babel/helper-compilation-targets@^7.12.16":
94+
version "7.12.16"
95+
resolved "https://registry.yarnpkg.com/@babel/helper-compilation-targets/-/helper-compilation-targets-7.12.16.tgz#6905238b4a5e02ba2d032c1a49dd1820fe8ce61b"
96+
integrity sha512-dBHNEEaZx7F3KoUYqagIhRIeqyyuI65xMndMZ3WwGwEBI609I4TleYQHcrS627vbKyNTXqShoN+fvYD9HuQxAg==
9797
dependencies:
9898
"@babel/compat-data" "^7.12.13"
99-
"@babel/helper-validator-option" "^7.12.11"
99+
"@babel/helper-validator-option" "^7.12.16"
100100
browserslist "^4.14.5"
101101
semver "^5.5.0"
102102

@@ -312,10 +312,10 @@
312312
resolved "https://registry.yarnpkg.com/@babel/helper-validator-identifier/-/helper-validator-identifier-7.9.5.tgz#90977a8e6fbf6b431a7dc31752eee233bf052d80"
313313
integrity sha512-/8arLKUFq882w4tWGj9JYzRpAlZgiWUJ+dtteNTDqrRBz9Iguck9Rn3ykuBDoUwh2TO4tSAJlrxDUOXWklJe4g==
314314

315-
"@babel/helper-validator-option@^7.12.11":
316-
version "7.12.11"
317-
resolved "https://registry.yarnpkg.com/@babel/helper-validator-option/-/helper-validator-option-7.12.11.tgz#d66cb8b7a3e7fe4c6962b32020a131ecf0847f4f"
318-
integrity sha512-TBFCyj939mFSdeX7U7DDj32WtzYY7fDcalgq8v3fBZMNOJQNn7nOYzMaUCiPxPYfCup69mtIpqlKgMZLvQ8Xhw==
315+
"@babel/helper-validator-option@^7.12.16":
316+
version "7.12.16"
317+
resolved "https://registry.yarnpkg.com/@babel/helper-validator-option/-/helper-validator-option-7.12.16.tgz#f73cbd3bbba51915216c5dea908e9b206bb10051"
318+
integrity sha512-uCgsDBPUQDvzr11ePPo4TVEocxj8RXjUVSC/Y8N1YpVAI/XDdUwGJu78xmlGhTxj2ntaWM7n9LQdRtyhOzT2YQ==
319319

320320
"@babel/helper-wrap-function@^7.12.13":
321321
version "7.12.13"
@@ -368,6 +368,11 @@
368368
resolved "https://registry.yarnpkg.com/@babel/parser/-/parser-7.12.15.tgz#2b20de7f0b4b332d9b119dd9c33409c538b8aacf"
369369
integrity sha512-AQBOU2Z9kWwSZMd6lNjCX0GUgFonL1wAM1db8L8PMk9UDaGsRCArBkU4Sc+UCM3AE4hjbXx+h58Lb3QT4oRmrA==
370370

371+
"@babel/parser@^7.12.16":
372+
version "7.12.16"
373+
resolved "https://registry.yarnpkg.com/@babel/parser/-/parser-7.12.16.tgz#cc31257419d2c3189d394081635703f549fc1ed4"
374+
integrity sha512-c/+u9cqV6F0+4Hpq01jnJO+GLp2DdT63ppz9Xa+6cHaajM9VFzK/iDXiKK65YtpeVwu+ctfS6iqlMqRgQRzeCw==
375+
371376
"@babel/parser@^7.7.0", "@babel/parser@^7.9.6":
372377
version "7.9.6"
373378
resolved "https://registry.yarnpkg.com/@babel/parser/-/parser-7.9.6.tgz#3b1bbb30dabe600cd72db58720998376ff653bc7"
@@ -395,12 +400,12 @@
395400
"@babel/helper-create-class-features-plugin" "^7.12.13"
396401
"@babel/helper-plugin-utils" "^7.12.13"
397402

398-
"@babel/plugin-proposal-dynamic-import@^7.12.1":
399-
version "7.12.1"
400-
resolved "https://registry.yarnpkg.com/@babel/plugin-proposal-dynamic-import/-/plugin-proposal-dynamic-import-7.12.1.tgz#43eb5c2a3487ecd98c5c8ea8b5fdb69a2749b2dc"
401-
integrity sha512-a4rhUSZFuq5W8/OO8H7BL5zspjnc1FLd9hlOxIK/f7qG4a0qsqk8uvF/ywgBA8/OmjsapjpvaEOYItfGG1qIvQ==
403+
"@babel/plugin-proposal-dynamic-import@^7.12.16":
404+
version "7.12.16"
405+
resolved "https://registry.yarnpkg.com/@babel/plugin-proposal-dynamic-import/-/plugin-proposal-dynamic-import-7.12.16.tgz#b9f33b252e3406d492a15a799c9d45a9a9613473"
406+
integrity sha512-yiDkYFapVxNOCcBfLnsb/qdsliroM+vc3LHiZwS4gh7pFjo5Xq3BDhYBNn3H3ao+hWPvqeeTdU+s+FIvokov+w==
402407
dependencies:
403-
"@babel/helper-plugin-utils" "^7.10.4"
408+
"@babel/helper-plugin-utils" "^7.12.13"
404409
"@babel/plugin-syntax-dynamic-import" "^7.8.0"
405410

406411
"@babel/plugin-proposal-export-namespace-from@^7.12.13":
@@ -460,10 +465,10 @@
460465
"@babel/helper-plugin-utils" "^7.12.13"
461466
"@babel/plugin-syntax-optional-catch-binding" "^7.8.0"
462467

463-
"@babel/plugin-proposal-optional-chaining@^7.12.13":
464-
version "7.12.13"
465-
resolved "https://registry.yarnpkg.com/@babel/plugin-proposal-optional-chaining/-/plugin-proposal-optional-chaining-7.12.13.tgz#63a7d805bc8ce626f3234ee5421a2a7fb23f66d9"
466-
integrity sha512-0ZwjGfTcnZqyV3y9DSD1Yk3ebp+sIUpT2YDqP8hovzaNZnQq2Kd7PEqa6iOIUDBXBt7Jl3P7YAcEIL5Pz8u09Q==
468+
"@babel/plugin-proposal-optional-chaining@^7.12.16":
469+
version "7.12.16"
470+
resolved "https://registry.yarnpkg.com/@babel/plugin-proposal-optional-chaining/-/plugin-proposal-optional-chaining-7.12.16.tgz#600c7531f754186b0f2096e495a92da7d88aa139"
471+
integrity sha512-O3ohPwOhkwji5Mckb7F/PJpJVJY3DpPsrt/F0Bk40+QMk9QpAIqeGusHWqu/mYqsM8oBa6TziL/2mbERWsUZjg==
467472
dependencies:
468473
"@babel/helper-plugin-utils" "^7.12.13"
469474
"@babel/helper-skip-transparent-expression-wrappers" "^7.12.1"
@@ -833,27 +838,27 @@
833838
"@babel/helper-create-regexp-features-plugin" "^7.12.13"
834839
"@babel/helper-plugin-utils" "^7.12.13"
835840

836-
"@babel/preset-env@^7.12.13":
837-
version "7.12.13"
838-
resolved "https://registry.yarnpkg.com/@babel/preset-env/-/preset-env-7.12.13.tgz#3aa2d09cf7d255177538dff292ac9af29ad46525"
839-
integrity sha512-JUVlizG8SoFTz4LmVUL8++aVwzwxcvey3N0j1tRbMAXVEy95uQ/cnEkmEKHN00Bwq4voAV3imQGnQvpkLAxsrw==
841+
"@babel/preset-env@^7.12.16":
842+
version "7.12.16"
843+
resolved "https://registry.yarnpkg.com/@babel/preset-env/-/preset-env-7.12.16.tgz#16710e3490e37764b2f41886de0a33bc4ae91082"
844+
integrity sha512-BXCAXy8RE/TzX416pD2hsVdkWo0G+tYd16pwnRV4Sc0fRwTLRS/Ssv8G5RLXUGQv7g4FG7TXkdDJxCjQ5I+Zjg==
840845
dependencies:
841846
"@babel/compat-data" "^7.12.13"
842-
"@babel/helper-compilation-targets" "^7.12.13"
847+
"@babel/helper-compilation-targets" "^7.12.16"
843848
"@babel/helper-module-imports" "^7.12.13"
844849
"@babel/helper-plugin-utils" "^7.12.13"
845-
"@babel/helper-validator-option" "^7.12.11"
850+
"@babel/helper-validator-option" "^7.12.16"
846851
"@babel/plugin-proposal-async-generator-functions" "^7.12.13"
847852
"@babel/plugin-proposal-class-properties" "^7.12.13"
848-
"@babel/plugin-proposal-dynamic-import" "^7.12.1"
853+
"@babel/plugin-proposal-dynamic-import" "^7.12.16"
849854
"@babel/plugin-proposal-export-namespace-from" "^7.12.13"
850855
"@babel/plugin-proposal-json-strings" "^7.12.13"
851856
"@babel/plugin-proposal-logical-assignment-operators" "^7.12.13"
852857
"@babel/plugin-proposal-nullish-coalescing-operator" "^7.12.13"
853858
"@babel/plugin-proposal-numeric-separator" "^7.12.13"
854859
"@babel/plugin-proposal-object-rest-spread" "^7.12.13"
855860
"@babel/plugin-proposal-optional-catch-binding" "^7.12.13"
856-
"@babel/plugin-proposal-optional-chaining" "^7.12.13"
861+
"@babel/plugin-proposal-optional-chaining" "^7.12.16"
857862
"@babel/plugin-proposal-private-methods" "^7.12.13"
858863
"@babel/plugin-proposal-unicode-property-regex" "^7.12.13"
859864
"@babel/plugin-syntax-async-generators" "^7.8.0"

0 commit comments

Comments
 (0)