Created
January 11, 2022 08:13
-
-
Save dagi3d/acde11c1facc881f3bfd9adaa047415c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { NotFoundError } from './errors'; | |
export default class QueryResult { | |
constructor(p = Promise.resolve()) { | |
this.promise = p; | |
} | |
null() { | |
return new this.constructor((async () => { | |
try { | |
return await this.promise; | |
} catch (err) { | |
if (err instanceof NotFoundError) return null; | |
throw err; | |
} | |
})()); | |
} | |
then(...args) { | |
return this.promise.then(...args); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment