Server
Errors

Errors

const isAuthedResolver = resolver.use(({ ctx, next }) => {
  if (!ctx.user)
    throw new PtsqError({
      code: PtsqErrorCode.UNAUTHORIZED_401,
      message: 'Must be logged in!',
    });
 
  return next({
    ctx: {
      user: ctx.user,
    },
  });
});

The PtsqError is the only error that is caught by the ptsq. The adapter such as Express or Koa then responds with that error code and message, if specified. You can also specify info, which can be something like a schema validation error.

throw new PtsqError({
  code: PtsqErrorCode.BAD_REQUEST_400,
  message: 'User already exists.',
  info: databaseInsert.error,
});