Skip to content

Commit de1cbb5

Browse files
committed
use typescript overloading to retain old log signature
1 parent 1c635c1 commit de1cbb5

File tree

1 file changed

+31
-3
lines changed

1 file changed

+31
-3
lines changed

src/log.ts

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,32 @@ export class Log {
5656
podName: string,
5757
containerName: string,
5858
stream: Writable,
59-
options: LogOptions = {},
59+
options?: LogOptions,
60+
): Promise<request.Request>;
61+
/** @deprecated done callback is deprecated */
62+
public async log(
63+
namespace: string,
64+
podName: string,
65+
containerName: string,
66+
stream: Writable,
67+
done: (err: any) => void,
68+
options?: LogOptions,
69+
): Promise<request.Request>;
70+
public async log(
71+
namespace: string,
72+
podName: string,
73+
containerName: string,
74+
stream: Writable,
75+
doneOrOptions?: ((err: any) => void) | LogOptions,
76+
options?: LogOptions,
6077
): Promise<request.Request> {
78+
let done: (err: any) => void = () => undefined;
79+
if (typeof doneOrOptions === 'function') {
80+
done = doneOrOptions;
81+
} else {
82+
options = doneOrOptions;
83+
}
84+
6185
const path = `/api/v1/namespaces/${namespace}/pods/${podName}/log`;
6286

6387
const cluster = this.config.getCurrentCluster();
@@ -80,9 +104,13 @@ export class Log {
80104
const req = request(requestOptions, (error, response, body) => {
81105
if (error) {
82106
reject(error);
107+
done(error);
83108
} else if (response.statusCode !== 200) {
84-
body = ObjectSerializer.deserialize(JSON.parse(body), 'V1Status');
85-
reject(new HttpError(response, body, response.statusCode));
109+
const deserializedBody = ObjectSerializer.deserialize(JSON.parse(body), 'V1Status');
110+
reject(new HttpError(response, deserializedBody, response.statusCode));
111+
done(body);
112+
} else {
113+
done(null);
86114
}
87115
}).on('response', (response) => {
88116
if (response.statusCode === 200) {

0 commit comments

Comments
 (0)