Skip to content

Commit d359e58

Browse files
authored
Merge pull request #3 from kapetacom/widen-generic-execute
Widen the type boundary for ReturnData
2 parents f01e011 + 1c12b02 commit d359e58

File tree

1 file changed

+5
-6
lines changed

1 file changed

+5
-6
lines changed

index.ts

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -62,11 +62,7 @@ export class RestClient {
6262
* @param {RequestArgument[]} requestArguments An array of request arguments.
6363
* @return {Promise<ReturnData | null>} The result of the request, or null if the response status is 404.
6464
*/
65-
async execute<ReturnData extends Record<string, unknown> = any>(
66-
method: RequestMethod,
67-
path: string,
68-
requestArguments: RequestArgument[] = []
69-
) {
65+
async execute<ReturnData = any>(method: RequestMethod, path: string, requestArguments: RequestArgument[] = []) {
7066
while (path.startsWith('/')) {
7167
path = path.substring(1);
7268
}
@@ -124,7 +120,10 @@ export class RestClient {
124120
}
125121

126122
if (result.status >= 400) {
127-
const error = (output?.error ?? 'Unknown error') as string;
123+
const error =
124+
output && typeof output === 'object' && 'error' in output && typeof output.error === 'string'
125+
? output.error
126+
: 'Unknown error';
128127
throw new RestError(error, result);
129128
}
130129

0 commit comments

Comments
 (0)