Server
Errors

Errors

Error in middleware
const isAuthedResolver = resolver.use(({ ctx, next }) => {
  if (!ctx.user)
    throw new PtsqError({
      code: 'UNAUTHORIZED',
      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 cause, which can be something like a schema validation error.

throw new PtsqError({
  code: 'BAD_REQUEST',
  message: 'User already exists.',
  cause: databaseInsert.error,
});

Error codes

PtsqError codeDescriptionHTTP status
PTSQ_VALIDATION_FAILEDThe arguments schema validation failed.400
PTSQ_BODY_PARSE_FAILEDThe server cannot parse the request body or the body is in bad format.400
PTSQ_BAD_ROUTE_TYPEThe route is query and should be mutation and vice versa.400
BAD_REQUESTThe server cannot or will not process the request due to something that is perceived to be a client error.400
UNAUTHORIZEDThe client request has not been completed because it lacks valid authentication credentials for the requested resource.401
FORBIDDENThe server was unauthorized to access a PTSQ endpoint.403
NOT_FOUNDThe server cannot find the requested PTSQ endpoint.404
METHOD_NOT_SUPPORTEDThe server knows the request method, but the target resource doesn't support this method.405
TIMEOUTThe server would like to shut down this unused connection.408
CONFLICTThe server request resource conflict with the current state of the target resource.409
PRECONDITION_FAILEDAccess to the target resource has been denied.412
PAYLOAD_TOO_LARGERequest entity is larger than limits defined by server.413
UNPROCESSABLE_CONTENTThe server understands the request method, and the request entity is correct, but the server was unable to process it.422
TOO_MANY_REQUESTSThe rate limit has been exceeded or too many requests are being sent to the server.429
CLIENT_CLOSED_REQUESTAccess to the resource has been denied.499
INTERNAL_SERVER_ERRORThe output validation failed or an unspecified error occurred.500