mochi/error

Types

Error category for extensions

pub type ErrorCategory {
  ValidationErrorCategory
  ResolverErrorCategory
  TypeErrorCategory
  AuthenticationErrorCategory
  AuthorizationErrorCategory
  InternalErrorCategory
  UserInputErrorCategory
}

Constructors

  • ValidationErrorCategory
  • ResolverErrorCategory
  • TypeErrorCategory
  • AuthenticationErrorCategory
  • AuthorizationErrorCategory
  • InternalErrorCategory
  • UserInputErrorCategory
pub type ErrorCode {
  NotFound
  Unauthorized
  Forbidden
  BadRequest
  InternalError
}

Constructors

  • NotFound
  • Unauthorized
  • Forbidden
  • BadRequest
  • InternalError
pub type GqlError =
  GraphQLError

GraphQL-spec compliant error with extensions support

pub type GraphQLError {
  GraphQLError(
    message: String,
    locations: option.Option(List(Location)),
    path: option.Option(List(PathSegment)),
    extensions: option.Option(dict.Dict(String, dynamic.Dynamic)),
  )
}

Constructors

A GraphQL source location

pub type Location {
  Location(line: Int, column: Int)
}

Constructors

  • Location(line: Int, column: Int)

Path segment - can be field name or array index

pub type PathSegment {
  FieldSegment(name: String)
  IndexSegment(index: Int)
}

Constructors

  • FieldSegment(name: String)
  • IndexSegment(index: Int)

Values

pub fn append_field(
  path: List(PathSegment),
  field: String,
) -> List(PathSegment)

Add field segment to path

pub fn append_index(
  path: List(PathSegment),
  index: Int,
) -> List(PathSegment)

Add index segment to path

pub fn at_location(
  err: GraphQLError,
  line: Int,
  column: Int,
) -> GraphQLError

Add a location to an error

pub fn authentication_error(message: String) -> GraphQLError
pub fn authorization_error(
  message: String,
  path: List(String),
) -> GraphQLError

Create an authorization error

pub fn code_to_string(code: ErrorCode) -> String
pub fn errors_to_dynamic(
  errors: List(GraphQLError),
) -> dynamic.Dynamic

Convert multiple errors to a list

pub fn fail(message: String) -> Result(r, GraphQLError)
pub fn format(err: GraphQLError) -> String

Format an error as a human-readable string

pub fn internal_error(message: String) -> GraphQLError
pub fn new(message: String) -> GraphQLError
pub fn new_at(
  message: String,
  path: List(String),
) -> GraphQLError
pub fn new_with_path(
  message: String,
  path: List(PathSegment),
) -> GraphQLError
pub fn path_from_strings(path: List(String)) -> List(PathSegment)

Convert string path to PathSegment list

pub fn resolver_error(
  message: String,
  path: List(String),
) -> GraphQLError

Create a resolver error

pub fn to_dynamic(err: GraphQLError) -> dynamic.Dynamic

Convert a GraphQLError to a Dynamic representation for JSON serialization

pub fn to_payload(
  err: GraphQLError,
) -> #(String, option.Option(dict.Dict(String, dynamic.Dynamic)))
pub fn type_error(
  message: String,
  path: List(String),
) -> GraphQLError

Create a type error

pub fn user_input_error(
  message: String,
  field: String,
  path: List(String),
) -> GraphQLError

Create a user input error

pub fn validation_error(
  message: String,
  path: List(String),
) -> GraphQLError

Create a validation error

pub fn with_category(
  err: GraphQLError,
  category: ErrorCategory,
) -> GraphQLError

Set error category in extensions

pub fn with_code(err: GraphQLError, code: String) -> GraphQLError

Set error code in extensions

pub fn with_error_code(
  err: GraphQLError,
  code: ErrorCode,
) -> GraphQLError
pub fn with_extension(
  err: GraphQLError,
  key: String,
  value: dynamic.Dynamic,
) -> GraphQLError

Add an extension to an error

pub fn with_extensions(
  err: GraphQLError,
  extensions: dict.Dict(String, dynamic.Dynamic),
) -> GraphQLError

Set multiple extensions on an error

pub fn with_locations(
  err: GraphQLError,
  locations: List(Location),
) -> GraphQLError

Add locations to an error

pub fn with_path(
  err: GraphQLError,
  path: List(PathSegment),
) -> GraphQLError

Set the path on an error

Search Document