gRPC & High Performance APIs · Ders

google.rpc.Status ile Zengin Hata Modelleri

Yapılandırılmış, makine tarafından okunabilir hata ayrıntılarını google.rpc.Status modeli ve standart hata ayrıntısı türlerini kullanarak ekleyin; basit durum kodlarının ötesine geçin.

4. ders / 413 adım

google.rpc.Status ile Zengin Hata Modelleri, CoddyKit'te ücretsiz bir gRPC & High Performance APIs dersidir. Bu, 4 dersinin 4. dersidir. Aşağıdan dersin tamamını ücretsiz okuyabilir, sonra tarayıcıda yerleşik kod editörü ve 7/24 yapay zeka koçu ile uygulamalı olarak pratik yapabilirsin. Bu, gRPC & High Performance APIs öğrenme yolunun bir parçasıdır ve ilerlemeniz web ve CoddyKit uygulaması arasında senkronize olur. gRPC & High Performance APIs kursu toplamda 4 dersten oluşur.

Bu dersin bazı bölümleri henüz çevrilmemiş olup İngilizce olarak gösterilmektedir.

Limits of Plain Status Codes

A bare status code plus a message tells the client that something failed, but not the structured why. Clients often need field-level validation errors, retry hints, or quota info.

The rich error model attaches structured details to a status.

The google.rpc.Status Message

The core type is google.rpc.Status with three fields:

  • code: a numeric status code
  • message: developer-facing text
  • details: a repeated list of Any payloads

Standard Detail Types

Google defines reusable detail messages in google/rpc/error_details.proto:

  • BadRequest — field violations
  • RetryInfo — when to retry
  • QuotaFailure — limit exceeded
  • ErrorInfo — machine-readable reason

BadRequest for Validation

BadRequest carries a list of FieldViolation entries, each naming a bad field and describing the problem. Perfect for form validation responses.

Building a Rich Error in Go

The status package lets you create a status and append typed details with WithDetails.

st := status.New(codes.InvalidArgument, 'invalid request')
v := &errdetails.BadRequest_FieldViolation{
  Field: 'email', Description: 'must be a valid address',
}
br := &errdetails.BadRequest{FieldViolations: []*errdetails.BadRequest_FieldViolation{v}}
st, _ = st.WithDetails(br)
return st.Err()

RetryInfo for Backoff Hints

For temporary failures, attach RetryInfo with a retry_delay. A well-behaved client reads this and waits before retrying.

ri := &errdetails.RetryInfo{RetryDelay: durationpb.New(2 * time.Second)}
st, _ = status.New(codes.Unavailable, 'busy').WithDetails(ri)

ErrorInfo for Stable Reasons

ErrorInfo gives a stable reason string and a domain plus metadata. Unlike free-text messages, clients can branch on these reliably.

ei := &errdetails.ErrorInfo{
  Reason: 'EMAIL_TAKEN', Domain: 'auth.example.com',
}

Reading Details on the Client

The client converts the returned error back to a status and inspects each detail with a type switch.

st := status.Convert(err)
for _, d := range st.Details() {
  switch t := d.(type) {
  case *errdetails.BadRequest:
    handleFieldErrors(t)
  case *errdetails.RetryInfo:
    waitThenRetry(t.RetryDelay)
  }
}

How Details Travel

Details are serialized into the grpc-status-details-bin trailer as a binary Status proto. Languages with the rich-error libraries decode it automatically.

Best Practices

Use the rich model wisely:

  • Prefer standard detail types for interoperability
  • Never leak secrets in messages or details
  • Keep ErrorInfo.reason values stable and documented
  • Pair RetryInfo with truly retryable codes

Cross-Language Interop

Because the model is defined in protobuf, a Go server can emit a BadRequest that a Java or Python client decodes identically. This consistency is the whole point of the standard types.

Quick Check

Test your rich error knowledge.

Recap

You learned the rich error model:

  • google.rpc.Status carries code, message, and repeated detail Any payloads
  • Standard types: BadRequest, RetryInfo, QuotaFailure, ErrorInfo
  • Build with WithDetails, read with a type switch over Details()
  • Details travel in the grpc-status-details-bin trailer
  • Standard types give cross-language consistency
Başlamak ücretsiz

Yapay zeka eğitmeniyle gRPC & High Performance APIs öğren — ücretsiz

Tarayıcında gerçek kod yaz ve çalıştır, 7/24 yapay zeka eğitmeninden anında yardım al; web'de ya da uygulamada kaldığın yerden devam et.

Kurslar
12
Dersler
48

Sıkça Sorulan Sorular

“google.rpc.Status ile Zengin Hata Modelleri” dersi ücretsiz mi?

Evet — “google.rpc.Status ile Zengin Hata Modelleri” dersin tüm metni burada web'de ücretsiz olarak okunabilir. Etkileşimli olarak pratik yapmak (yerleşik kod editörü ve 7/24 yapay zeka koçu) ve gRPC & High Performance APIs kursunun geri kalanını açmak için CoddyKit PRO'ya yükselt. gRPC & High Performance APIs kursu toplamda 4 dersten oluşur.

“google.rpc.Status ile Zengin Hata Modelleri” dersinde ne öğreneceğim?

Yapılandırılmış, makine tarafından okunabilir hata ayrıntılarını google.rpc.Status modeli ve standart hata ayrıntısı türlerini kullanarak ekleyin; basit durum kodlarının ötesine geçin. gRPC & High Performance APIs ile uygulamalı kodu tarayıcıda doğrudan çalıştırarak pratik yaparsın ve 7/24 yapay zeka koçu dersi çalışırken sorularını yanıtlar.

gRPC & High Performance APIs öğrenmeye başlamak için deneyim gerekli mi?

Önceden deneyim gerekmez. CoddyKit'te gRPC & High Performance APIs, başlangıçtan ileri seviyeye kadar yapılandırıldığı için buradan başlayabilir veya başından başlayıp kendi hızında ilerleme yapabilirsin. Bu, 4 dersinin 4. dersidir.

“google.rpc.Status ile Zengin Hata Modelleri” dersi ne kadar sürer?

Çoğu CoddyKit dersi yaklaşık 5–10 dakika sürer. Her biri kısa ve etkileşimli olduğu için sabit ilerleme yaparsın ve web ile uygulama arasında tam olarak bıraktığın yerden devam edebilirsin.

Bu gRPC & High Performance APIs dersinde kod yazıp çalıştırabilir miyim?

Evet. Her gRPC & High Performance APIs dersi yerleşik bir kod editörü içerir, bu sayede tarayıcıda gerçek kod yazıp çalıştırabilir ve anlık yapay zeka geri bildirimi alırsın — yerel kurulum gerekli değildir.

Bu kursun tüm dersleri

  1. Durum Kodları ve Hata Yönetimi
  2. Özel Üst Veri İletimi
  3. Bağlam ve Son Tarihler
  4. google.rpc.Status ile Zengin Hata Modelleri
← gRPC & High Performance APIs Sayfasına Dön