Change response data
This commit is contained in:
parent
14791149c6
commit
e289abf1f8
|
@ -51,14 +51,14 @@ http
|
|||
logger.error(err);
|
||||
|
||||
res.writeHead(400, contentType);
|
||||
res.write(JSON.stringify({ response: "error", message: "Invalid content-type." }));
|
||||
res.write(response.error(err));
|
||||
res.end();
|
||||
});
|
||||
} else {
|
||||
logger.log(`${sender} cannot ${req.method} to ${req.url}`);
|
||||
|
||||
res.writeHead(400, contentType);
|
||||
res.write(response.error(`Cannot ${req.method} to '${req.url}'`));
|
||||
res.write(JSON.stringify({ error: { type: "generic", error: `Cannot ${req.method} to ${req.url}` }}));
|
||||
res.end();
|
||||
}
|
||||
});
|
||||
|
|
|
@ -1,17 +1,20 @@
|
|||
import { ValidationError } from "yup";
|
||||
|
||||
export class Responder {
|
||||
constructor() {}
|
||||
|
||||
public success(message: string): string {
|
||||
return JSON.stringify({
|
||||
response: "success",
|
||||
message: message
|
||||
});
|
||||
}
|
||||
|
||||
public error(message: string): string {
|
||||
public error(error: ValidationError): string {
|
||||
return JSON.stringify({
|
||||
response: "error",
|
||||
message: message
|
||||
})
|
||||
error: {
|
||||
type: error.name,
|
||||
message: error.message
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue