Change response data

This commit is contained in:
powermaker450 2024-08-18 22:45:02 -04:00
parent 14791149c6
commit e289abf1f8
2 changed files with 10 additions and 7 deletions

View file

@ -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();
}
});

View file

@ -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
}
});
}
}