write failed responses to stderr
This commit is contained in:
parent
802d38f52e
commit
a1823f9931
|
@ -10,15 +10,17 @@ import { UserService } from '../abstractions/user.service';
|
||||||
const chalk = chk.default;
|
const chalk = chk.default;
|
||||||
|
|
||||||
export abstract class BaseProgram {
|
export abstract class BaseProgram {
|
||||||
constructor(private userService: UserService, private writeLn: (s: string, finalLine: boolean) => void) { }
|
constructor(
|
||||||
|
private userService: UserService,
|
||||||
|
private writeLn: (s: string, finalLine: boolean, error: boolean) => void) { }
|
||||||
|
|
||||||
protected processResponse(response: Response, exitImmediately = false, dataProcessor: () => string = null) {
|
protected processResponse(response: Response, exitImmediately = false, dataProcessor: () => string = null) {
|
||||||
if (!response.success) {
|
if (!response.success) {
|
||||||
if (process.env.BW_QUIET !== 'true') {
|
if (process.env.BW_QUIET !== 'true') {
|
||||||
if (process.env.BW_RESPONSE === 'true') {
|
if (process.env.BW_RESPONSE === 'true') {
|
||||||
this.writeLn(this.getJson(response), true);
|
this.writeLn(this.getJson(response), true, true);
|
||||||
} else {
|
} else {
|
||||||
this.writeLn(chalk.redBright(response.message), true);
|
this.writeLn(chalk.redBright(response.message), true, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (exitImmediately) {
|
if (exitImmediately) {
|
||||||
|
@ -30,7 +32,7 @@ export abstract class BaseProgram {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (process.env.BW_RESPONSE === 'true') {
|
if (process.env.BW_RESPONSE === 'true') {
|
||||||
this.writeLn(this.getJson(response), true);
|
this.writeLn(this.getJson(response), true, false);
|
||||||
} else if (response.data != null) {
|
} else if (response.data != null) {
|
||||||
let out: string = dataProcessor != null ? dataProcessor() : null;
|
let out: string = dataProcessor != null ? dataProcessor() : null;
|
||||||
if (out == null) {
|
if (out == null) {
|
||||||
|
@ -49,7 +51,7 @@ export abstract class BaseProgram {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (out != null && process.env.BW_QUIET !== 'true') {
|
if (out != null && process.env.BW_QUIET !== 'true') {
|
||||||
this.writeLn(out, true);
|
this.writeLn(out, true, false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (exitImmediately) {
|
if (exitImmediately) {
|
||||||
|
|
Loading…
Reference in New Issue