fix(client): update request handling and typings for current smartrequest and OpenAPI output
This commit is contained in:
+29
-10
@@ -30,16 +30,35 @@ export class HetznerAccount {
|
||||
console.log(`Url: ${url}`);
|
||||
console.log(`Method: ${methodArg}`);
|
||||
console.log(`Payload: ${JSON.stringify(payloadArg, null, 2)}`);
|
||||
const response = await plugins.smartrequest.request(url, {
|
||||
method: methodArg,
|
||||
headers: {
|
||||
const request = plugins.smartrequest.SmartRequest.create()
|
||||
.url(url)
|
||||
.headers({
|
||||
Authorization: `Bearer ${this.token}`,
|
||||
},
|
||||
requestBody: payloadArg,
|
||||
keepAlive: false,
|
||||
});
|
||||
console.log(response.statusCode);
|
||||
console.log(response.body);
|
||||
return response;
|
||||
})
|
||||
.options({
|
||||
keepAlive: false,
|
||||
});
|
||||
|
||||
if (methodArg !== 'GET' && methodArg !== 'DELETE') {
|
||||
request.json(payloadArg);
|
||||
}
|
||||
|
||||
const response = methodArg === 'POST'
|
||||
? await request.post()
|
||||
: methodArg === 'PUT'
|
||||
? await request.put()
|
||||
: methodArg === 'PATCH'
|
||||
? await request.patch()
|
||||
: methodArg === 'DELETE'
|
||||
? await request.delete()
|
||||
: await request.get();
|
||||
const body = await response.json().catch(() => ({}));
|
||||
const responseObject = {
|
||||
statusCode: response.status,
|
||||
body,
|
||||
};
|
||||
console.log(responseObject.statusCode);
|
||||
console.log(responseObject.body);
|
||||
return responseObject;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user