fix: Advent22.api_put authorization

This commit is contained in:
Jörn-Michael Miehe 2023-09-12 22:35:40 +00:00
parent bd7bc38954
commit 6012cec657

View file

@ -56,14 +56,14 @@ export class Advent22 {
endpoint: string, endpoint: string,
responseType: ResponseType = "json", responseType: ResponseType = "json",
): Promise<T> { ): Promise<T> {
const req_data = { const req_config = {
auth: this.api_auth, auth: this.api_auth,
responseType: responseType, responseType: responseType,
}; };
return new Promise<T>((resolve, reject) => { return new Promise<T>((resolve, reject) => {
this.axios this.axios
.get<T>(this.api_url(endpoint), req_data) .get<T>(this.api_url(endpoint), req_config)
.then((response) => resolve(response.data)) .then((response) => resolve(response.data))
.catch((reason) => { .catch((reason) => {
console.error(`Failed to query ${endpoint}: ${reason}`); console.error(`Failed to query ${endpoint}: ${reason}`);
@ -95,9 +95,13 @@ export class Advent22 {
} }
public api_put(endpoint: string, data: unknown): Promise<void> { public api_put(endpoint: string, data: unknown): Promise<void> {
const req_config = {
auth: this.api_auth,
};
return new Promise<void>((resolve, reject) => return new Promise<void>((resolve, reject) =>
this.axios this.axios
.put(this.api_url(endpoint), data) .put(this.api_url(endpoint), data, req_config)
.then(() => resolve()) .then(() => resolve())
.catch(reject), .catch(reject),
); );