SpanStatus.fromHttpStatusCode constructor

SpanStatus.fromHttpStatusCode(
  1. int httpStatusCode, {
  2. SpanStatus? fallback,
})

Creates SpanStatus from HTTP status code.

Implementation

factory SpanStatus.fromHttpStatusCode(
  int httpStatusCode, {
  SpanStatus? fallback,
}) {
  var status = SpanStatus.ok();
  if (_matches(status, httpStatusCode)) {
    return status;
  }
  status = SpanStatus.cancelled();
  if (_matches(status, httpStatusCode)) {
    return status;
  }
  status = SpanStatus.unknown();
  if (_matches(status, httpStatusCode)) {
    return status;
  }
  status = SpanStatus.invalidArgument();
  if (_matches(status, httpStatusCode)) {
    return status;
  }
  status = SpanStatus.deadlineExceeded();
  if (_matches(status, httpStatusCode)) {
    return status;
  }
  status = SpanStatus.notFound();
  if (_matches(status, httpStatusCode)) {
    return status;
  }
  status = SpanStatus.alreadyExists();
  if (_matches(status, httpStatusCode)) {
    return status;
  }
  status = SpanStatus.permissionDenied();
  if (_matches(status, httpStatusCode)) {
    return status;
  }
  status = SpanStatus.resourceExhausted();
  if (_matches(status, httpStatusCode)) {
    return status;
  }
  status = SpanStatus.unimplemented();
  if (_matches(status, httpStatusCode)) {
    return status;
  }
  status = SpanStatus.unavailable();
  if (_matches(status, httpStatusCode)) {
    return status;
  }
  status = SpanStatus.unauthenticated();
  if (_matches(status, httpStatusCode)) {
    return status;
  }
  return fallback ?? SpanStatus.unknownError();
}