mirror of
https://github.com/n8n-io/n8n.git
synced 2025-01-13 05:47:31 -08:00
🔀 Merge pull request #432 from ceefour/json-fix
fix(cli): ResponseHelper sends JSON.
This commit is contained in:
commit
40943e7b83
|
@ -49,29 +49,26 @@ export class ResponseError extends Error {
|
||||||
export function basicAuthAuthorizationError(resp: Response, realm: string, message?: string) {
|
export function basicAuthAuthorizationError(resp: Response, realm: string, message?: string) {
|
||||||
resp.statusCode = 401;
|
resp.statusCode = 401;
|
||||||
resp.setHeader('WWW-Authenticate', `Basic realm="${realm}"`);
|
resp.setHeader('WWW-Authenticate', `Basic realm="${realm}"`);
|
||||||
resp.end(message);
|
resp.json({code: resp.statusCode, message});
|
||||||
}
|
}
|
||||||
|
|
||||||
export function jwtAuthAuthorizationError(resp: Response, message?: string) {
|
export function jwtAuthAuthorizationError(resp: Response, message?: string) {
|
||||||
resp.statusCode = 403;
|
resp.statusCode = 403;
|
||||||
resp.end(message);
|
resp.json({code: resp.statusCode, message});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
export function sendSuccessResponse(res: Response, data: any, raw?: boolean, responseCode?: number) { // tslint:disable-line:no-any
|
export function sendSuccessResponse(res: Response, data: any, raw?: boolean, responseCode?: number) { // tslint:disable-line:no-any
|
||||||
res.setHeader('Content-Type', 'application/json');
|
|
||||||
|
|
||||||
if (responseCode !== undefined) {
|
if (responseCode !== undefined) {
|
||||||
res.status(responseCode);
|
res.status(responseCode);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (raw === true) {
|
if (raw === true) {
|
||||||
res.send(JSON.stringify(data));
|
res.json(data);
|
||||||
return;
|
|
||||||
} else {
|
} else {
|
||||||
res.send(JSON.stringify({
|
res.json({
|
||||||
data
|
data
|
||||||
}));
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -103,7 +100,7 @@ export function sendErrorResponse(res: Response, error: ResponseError) {
|
||||||
response.stack = error.stack;
|
response.stack = error.stack;
|
||||||
}
|
}
|
||||||
|
|
||||||
res.status(httpStatusCode).send(JSON.stringify(response));
|
res.status(httpStatusCode).json(response);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue