Skip to content

Commit

Permalink
feat(storage-client): more data validate on get
Browse files Browse the repository at this point in the history
  • Loading branch information
alimd committed Dec 17, 2022
1 parent eaab2ae commit 4a8200c
Showing 1 changed file with 17 additions and 9 deletions.
26 changes: 17 additions & 9 deletions core/storage-client/src/storage-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,15 +110,23 @@ export class AlwatrStorageClient<DocumentType extends AlwatrDocumentObject = Alw
this._logger.logMethodArgs('get', {documentId});
if (storage == null) throw new Error('storage_not_defined');

return (
await serviceRequest<T>({
...this.fetchOption,
queryParameters: {
storage,
id: documentId,
},
})
).data;
const responseJson = await serviceRequest<T>({
...this.fetchOption,
queryParameters: {
storage,
id: documentId,
},
});

if (
typeof responseJson.data !== 'object' ||
typeof responseJson.data.id !== 'string'
) {
this._logger.error('get', 'invalid_response_data', {responseJson});
throw new Error('invalid_response_data');
}

return responseJson.data;
}

/**
Expand Down

0 comments on commit 4a8200c

Please sign in to comment.