Home

onErrorlike

OnErrorlike is a term used in discussions of error handling and type design to describe values or handlers that relate to errors but are not necessarily actual instances of the Error class. The concept often appears in the context of duck typing and flexible type systems, where an object can be treated as error-like if it exposes enough properties to convey an error condition.

In type design, an error-like shape is sometimes referred to as ErrorLike. Commonly, such objects include at

A typical use pattern is to define a type or interface that captures the minimal required properties

In API design, the term onErrorlike can also inform naming conventions for callbacks or event handlers that

See also: Error, ErrorEvent, duck typing, ErrorLike.

least
a
message
string
and
may
optionally
provide
a
name
and
a
stack
trace.
Because
ErrorLike
does
not
require
the
value
to
be
a
true
Error
instance,
code
can
accept
either
a
real
Error
or
an
error-like
object
and
respond
accordingly.
This
approach
can
improve
interoperability
when
dealing
with
diverse
data
sources,
such
as
JSON
payloads
or
cross-origin
error
information.
for
an
error-like
value
and
then
implement
a
type
guard
to
differentiate
between
genuine
Error
objects
and
error-like
shapes.
For
example,
a
function
might
accept
ErrorLike
|
string
and
handle
each
case,
or
a
consumer
might
normalize
various
inputs
into
a
canonical
Error
before
proceeding
with
standard
error
handling.
receive
error-like
input,
analogous
to
onerror
in
the
DOM.
It
emphasizes
recognizing
error
information
even
when
it
is
not
a
formal
error
object.