Skip to content

Instantly share code, notes, and snippets.

@dagi3d
Created January 11, 2022 08:13
Show Gist options
  • Save dagi3d/acde11c1facc881f3bfd9adaa047415c to your computer and use it in GitHub Desktop.
Save dagi3d/acde11c1facc881f3bfd9adaa047415c to your computer and use it in GitHub Desktop.
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