feat: error handling

This commit is contained in:
cha0s 2020-05-21 08:57:13 -05:00
parent 7e4e3e12ee
commit a424101ee3

View File

@ -9,7 +9,20 @@ export class Packet {
static get builder() {
if (!this._builder) {
this._builder = schemapack.build(this.schema);
const schema = this.schema;
if (!schema._id) {
throw new Error([
`No packet id found in '${this.name}.schema'. This is usually due to forgetting to`,
'inherit from Packet.schema within your packet subclass schema definition.',
].join(' '));
}
if (!schema.data) {
throw new Error([
`No data found in '${this.name}.schema'. This is usually due to forgetting to`,
'inherit from Packet.schema within your packet subclass schema definition.',
].join(' '));
}
this._builder = schemapack.build(schema);
}
return this._builder;
}