I have a DO with the following method: ```ts async reserve(): Promise<Result> { if (this.status !

I have a DO with the following method:

async reserve(): Promise<Result> {
  if (this.status !== "available") {
    const err = new ResultError("IDENTIFIER_NOT_AVAILABLE");
    console.log(err);
    return {
      success: false,
      // errors: [new ResultError("IDENTIFIER_NOT_AVAILABLE")],
      errors: [err],
    };
  }
}


but when called like this:

const resolverStubId = this.env.IDENTIFIER_RESOLVER.idFromName(
    user.identifier,
);
const resolverStub = this.env.IDENTIFIER_RESOLVER.get(resolverStubId);
const reservationResult = await resolverStub.reserve();
if (reservationResult.success === false) {
  console.log(reservationResult.errors);
  return {
    success: false,
    errors: [
      ...reservationResult.errors,
      new ResultError("IDENTIFIER_COULD_NOT_BE_RESERVED"),
    ],
  };
}


it "loses" the fact that it's a
ResultError
, since the
console.log
s show:

ResultError
    at IdentifierResolver.reserve (file:///path-1/index.ts:54:16) {
  code: 'IDENTIFIER_NOT_AVAILABLE'
}
[
  ResultError
      at IdentifierResolver.reserve (file:///path-2/index.ts:54:16)
]


So somewhere in transit that information seems to get lost (notice how the
code
isn't printed anymore. even checks with
instanceof
fail)... how can i deal with this?
Was this page helpful?