Skip to content

Errors

Simfinity errors attach structured metadata to GraphQL errors through extensions. Use codes for application decisions and messages for human-readable feedback.

SimfinityError

javascript
import { SimfinityError } from '@simtlix/simfinity-js';

throw new SimfinityError(
  'A series with active seasons cannot be deleted',
  'SERIE_HAS_ACTIVE_SEASONS',
  409,
);

new SimfinityError(message, code, status) extends Error and sets:

javascript
{
  code: 'SERIE_HAS_ACTIVE_SEASONS',
  status: 409,
  timestamp: '...',
}

The timestamp is generated with Date#toUTCString(). Access values through extensions or getCode(), getStatus(), and getTimestamp(). No default code or status is assigned when those arguments are omitted.

extensions.status is error metadata. Your GraphQL server decides the HTTP response status; a GraphQL execution error can still arrive in an HTTP 200 response.

Authentication and authorization errors

These classes are available on simfinity.auth:

ExportDefault messageCodeStatus
UnauthenticatedError(message)Authentication requiredUNAUTHENTICATED401
ForbiddenError(message)Access deniedFORBIDDEN403
createAuthError(message, code = 'FORBIDDEN')Supplied messageSupplied code401 for UNAUTHENTICATED; otherwise 403

InternalServerError

javascript
import { InternalServerError } from '@simtlix/simfinity-js';

const wrapped = new InternalServerError('Catalog lookup failed', originalError);
console.error(wrapped.getCause());

This subclass uses code INTERNAL_SERVER_ERROR and retains the cause. It does not assign an HTTP-like status value automatically.

buildErrorFormatter

javascript
import { buildErrorFormatter } from '@simtlix/simfinity-js';

const normalizeError = buildErrorFormatter((error) => {
  console.error(error.getCode(), error.message);
  // Return a replacement error, or return nothing to keep this error.
});

The returned function preserves SimfinityError instances and wraps other errors in InternalServerError, retaining the original message and cause. It is a standalone helper; integrate it into your server's own error-handling hook.

The helper checks the error instance it receives. If your server wraps an application error inside GraphQLError.originalError, choose the appropriate underlying error before normalizing it. This helper does not automatically redact unexpected-error messages.

Core error codes

CodeTrigger
VALIDATION_ERRORA declarative field validator rejects a value.
INPUT_TYPE_UNRESOLVEDInput generation cannot resolve registered relationships or dependencies.
MISSING_RELATION_EXTENSIONAn object field used during materialization lacks relationship metadata.
INVALID_FILTER_FIELDA logical filter condition names an unknown field.
INVALID_FILTER_PATHA filter path has an invalid structure or segment.
MISSING_FILTER_PATHA logical condition on an object field omits its related field path.
INVALID_FILTER_VALUEAn array-valued filter has an invalid value shape.
FILTER_DEPTH_EXCEEDEDA recursive filter group exceeds the supported nesting limit.
NOT_VALID_IDA state action targets a record that does not exist.
BAD_REQUESTA state action is not allowed from the record's current state.

This table covers intentional core errors; GraphQL coercion, Mongoose, and MongoDB can also produce their own errors. MCP returns execution failures as tool results and throws some setup/dispatch errors; see MCP error handling.

Open source. Released under the Apache 2.0 License.