more error handling
This commit is contained in:
parent
ed2bc49b0c
commit
b9f1bb5e53
2 changed files with 13 additions and 2 deletions
|
@ -75,8 +75,14 @@ class SnowFlake {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
getUnixTime() {
|
getUnixTime() {
|
||||||
|
try {
|
||||||
return Number((BigInt(this.id) >> 22n) + 1420070400000n);
|
return Number((BigInt(this.id) >> 22n) + 1420070400000n);
|
||||||
}
|
}
|
||||||
|
catch {
|
||||||
|
console.error(`The ID is corrupted, it's ${this.id} when it should be some number.`);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
toString() {
|
toString() {
|
||||||
return this.id;
|
return this.id;
|
||||||
}
|
}
|
||||||
|
|
|
@ -73,7 +73,12 @@ class SnowFlake<x extends WeakKey>{
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
getUnixTime():number{
|
getUnixTime():number{
|
||||||
|
try{
|
||||||
return Number((BigInt(this.id)>>22n)+1420070400000n);
|
return Number((BigInt(this.id)>>22n)+1420070400000n);
|
||||||
|
}catch{
|
||||||
|
console.error(`The ID is corrupted, it's ${this.id} when it should be some number.`)
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
toString(){
|
toString(){
|
||||||
return this.id;
|
return this.id;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue