Skip to content

Commit

Permalink
use typescript overloading to retain old log signature
Browse files Browse the repository at this point in the history
  • Loading branch information
Legion2 committed Jul 29, 2021
1 parent 1c635c1 commit de1cbb5
Showing 1 changed file with 31 additions and 3 deletions.
34 changes: 31 additions & 3 deletions src/log.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,32 @@ export class Log {
podName: string,
containerName: string,
stream: Writable,
options: LogOptions = {},
options?: LogOptions,
): Promise<request.Request>;
/** @deprecated done callback is deprecated */
public async log(
namespace: string,
podName: string,
containerName: string,
stream: Writable,
done: (err: any) => void,
options?: LogOptions,
): Promise<request.Request>;
public async log(
namespace: string,
podName: string,
containerName: string,
stream: Writable,
doneOrOptions?: ((err: any) => void) | LogOptions,
options?: LogOptions,
): Promise<request.Request> {
let done: (err: any) => void = () => undefined;
if (typeof doneOrOptions === 'function') {
done = doneOrOptions;
} else {
options = doneOrOptions;
}

const path = `/api/v1/namespaces/${namespace}/pods/${podName}/log`;

const cluster = this.config.getCurrentCluster();
Expand All @@ -80,9 +104,13 @@ export class Log {
const req = request(requestOptions, (error, response, body) => {
if (error) {
reject(error);
done(error);
} else if (response.statusCode !== 200) {
body = ObjectSerializer.deserialize(JSON.parse(body), 'V1Status');
reject(new HttpError(response, body, response.statusCode));
const deserializedBody = ObjectSerializer.deserialize(JSON.parse(body), 'V1Status');
reject(new HttpError(response, deserializedBody, response.statusCode));
done(body);
} else {
done(null);
}
}).on('response', (response) => {
if (response.statusCode === 200) {
Expand Down

0 comments on commit de1cbb5

Please sign in to comment.