extendedCode function

String extendedCode(
  1. String typeUri,
  2. String local
)

Build an extended error code under a specification's own slug (SPEC ยง8.5).

typeUri is normally a generated library's typeUri, so the namespace cannot drift from the type's identity. The #response fragment is stripped: an error raised while handling a response still belongs to the bare slug.

Throws ArgumentError if the derived slug or local is malformed.

Implementation

String extendedCode(String typeUri, String local) {
  final slug = slugFromTypeUri(typeUri);
  if (!_localRe.hasMatch(local)) {
    throw ArgumentError.value(
      local,
      'local',
      'must match $_localRe (a lowercase first character, then letters, '
          'digits or underscores)',
    );
  }
  return '$slug:$local';
}