Skip to content

Commit 9d52157

Browse files
authored
Merge pull request #719 from dappnode/dapplion/fix-https-portal-client
Run schema validator on in HTTPs Portal list method
2 parents c2d983c + 891422f commit 9d52157

File tree

1 file changed

+5
-7
lines changed

1 file changed

+5
-7
lines changed

packages/dappmanager/src/modules/https-portal/apiClient.ts

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,10 @@ export class HttpsPortalApiClient {
8888
urlJoin(this.baseUrl, `/?format=json`)
8989
);
9090

91+
if (!ajv.validate(httpsPortalResponseSchema, entries)) {
92+
throw Error(`Invalid response: ${JSON.stringify(ajv.errors, null, 2)}`);
93+
}
94+
9195
return entries.map(entry => ({
9296
fromSubdomain: entry.from,
9397
toHost: entry.to
@@ -103,13 +107,7 @@ export class HttpsPortalApiClient {
103107
}
104108

105109
try {
106-
const response = JSON.parse(body);
107-
108-
if (!ajv.validate(httpsPortalResponseSchema, response)) {
109-
throw Error(`Invalid response: ${JSON.stringify(ajv.errors, null, 2)}`);
110-
}
111-
112-
return response;
110+
return JSON.parse(body);
113111
} catch (e) {
114112
throw Error(`Error parsing JSON ${e.message}\n${body}`);
115113
}

0 commit comments

Comments
 (0)