Package google.rpc
จัดทุกอย่างให้เป็นระเบียบอยู่เสมอด้วยคอลเล็กชัน
บันทึกและจัดหมวดหมู่เนื้อหาตามค่ากำหนดของคุณ
สถานะ
ประเภท Status
กำหนดโมเดลข้อผิดพลาดเชิงตรรกะที่เหมาะสำหรับสภาพแวดล้อมการเขียนโปรแกรมที่แตกต่างกัน ซึ่งรวมถึง REST API และ RPC API ใช้โดย gRPC โมเดลข้อผิดพลาดมีลักษณะดังนี้
- ใช้งานง่ายและเข้าใจได้ง่ายสำหรับผู้ใช้ส่วนใหญ่
- ยืดหยุ่นพอที่จะตอบสนองความต้องการที่ไม่คาดคิด
ภาพรวม
ข้อความ Status
ประกอบด้วยข้อมูล 3 ส่วน ได้แก่ รหัสข้อผิดพลาด ข้อความแสดงข้อผิดพลาด และรายละเอียดข้อผิดพลาด รหัสข้อผิดพลาดควรเป็นค่า enum ของ google.rpc.Code
แต่อาจยอมรับรหัสข้อผิดพลาดเพิ่มเติมได้หากจําเป็น ข้อความแสดงข้อผิดพลาดควรเป็นข้อความภาษาอังกฤษที่แสดงต่อนักพัฒนาแอปเพื่อช่วยให้นักพัฒนาแอปunderstandและunderstandข้อผิดพลาดดังกล่าว หากต้องมีข้อความแสดงข้อผิดพลาดที่แสดงต่อผู้ใช้ในภาษาท้องถิ่น ให้ใส่ข้อความที่แปลแล้วในรายละเอียดข้อผิดพลาดหรือแปลข้อความในไคลเอ็นต์ รายละเอียดข้อผิดพลาดที่ไม่บังคับอาจมีข้อมูลที่กําหนดเองเกี่ยวกับข้อผิดพลาดนั้น ในแพ็กเกจ google.rpc
มีชุดรายละเอียดประเภทข้อผิดพลาดที่กำหนดไว้ล่วงหน้าซึ่งใช้สำหรับเงื่อนไขข้อผิดพลาดที่พบบ่อยได้
การแมปภาษา
ข้อความ Status
คือการแสดงโมเดลข้อผิดพลาดเชิงตรรกะ แต่ไม่จำเป็นต้องเป็นรูปแบบสายไฟจริง เมื่อข้อความ Status
ปรากฏในไลบรารีของไคลเอ็นต์และโปรโตคอลสายที่ต่างกัน ข้อความก็จะแมปต่างกันได้ ตัวอย่างเช่น อาจมีการแมปกับข้อยกเว้นบางอย่างใน Java แต่มีแนวโน้มที่จะแมปกับรหัสข้อผิดพลาดบางรหัสใน C
การใช้งานอื่นๆ
โมเดลข้อผิดพลาดและข้อความ Status
จะนำไปใช้ได้ในสภาพแวดล้อมต่างๆ ไม่ว่าจะมีหรือไม่มี API เพื่อให้นักพัฒนาซอฟต์แวร์ได้รับประสบการณ์ที่สอดคล้องกันในสภาพแวดล้อมต่างๆ ก็ตาม
ตัวอย่างการใช้รูปแบบข้อผิดพลาดนี้มีดังนี้
ข้อผิดพลาดบางส่วน หากบริการจำเป็นต้องส่งคืนข้อผิดพลาดบางส่วนไปยังไคลเอ็นต์ บริการอาจฝัง Status
ไว้ในการตอบสนองปกติเพื่อระบุข้อผิดพลาดบางส่วน
ข้อผิดพลาดของเวิร์กโฟลว์ เวิร์กโฟลว์ทั่วไปมีหลายขั้นตอน แต่ละขั้นตอนอาจมีข้อความ Status
สำหรับการรายงานข้อผิดพลาด
การทำงานเป็นกลุ่ม หากไคลเอ็นต์ใช้คำขอแบบกลุ่มและการตอบกลับแบบกลุ่ม คุณควรใช้ข้อความ Status
โดยตรงภายในการตอบกลับแบบกลุ่ม 1 รายการสำหรับการตอบกลับย่อยข้อผิดพลาดแต่ละรายการ
การดำเนินการอะซิงโครนัส หากการเรียก API ฝังผลลัพธ์การดำเนินการแบบอะซิงโครนัสในการตอบสนอง สถานะของการดำเนินการเหล่านั้นควรแสดงโดยตรงโดยใช้ข้อความ Status
การบันทึก หากจัดเก็บข้อผิดพลาดบางอย่างของ API ไว้ในบันทึก อาจมีการใช้ข้อความ Status
โดยตรงหลังจากตัดข้อความที่ไม่จำเป็นออกด้วยเหตุผลด้านความปลอดภัย/ความเป็นส่วนตัว
ช่อง |
code |
int32
รหัสสถานะ ซึ่งควรเป็นค่า enum ของ google.rpc.Code
|
message |
string
ข้อความแสดงข้อผิดพลาดที่ส่งถึงนักพัฒนาซอฟต์แวร์ ซึ่งควรเป็นภาษาอังกฤษ ข้อความแสดงข้อผิดพลาดที่แสดงต่อผู้ใช้ควรแปลและส่งในช่อง google.rpc.Status.details หรือไคลเอ็นต์แปล
|
details[] |
Any
รายการข้อความที่มีรายละเอียดข้อผิดพลาด มีชุดประเภทข้อความที่ใช้กันโดยทั่วไปสำหรับ API
|
เนื้อหาของหน้าเว็บนี้ได้รับอนุญาตภายใต้ใบอนุญาตที่ต้องระบุที่มาของครีเอทีฟคอมมอนส์ 4.0 และตัวอย่างโค้ดได้รับอนุญาตภายใต้ใบอนุญาต Apache 2.0 เว้นแต่จะระบุไว้เป็นอย่างอื่น โปรดดูรายละเอียดที่นโยบายเว็บไซต์ Google Developers Java เป็นเครื่องหมายการค้าจดทะเบียนของ Oracle และ/หรือบริษัทในเครือ
อัปเดตล่าสุด 2025-07-26 UTC
[null,null,["อัปเดตล่าสุด 2025-07-26 UTC"],[[["\u003cp\u003eThe \u003ccode\u003eStatus\u003c/code\u003e type defines a consistent and flexible error model suitable for various programming environments, including REST APIs and RPC APIs.\u003c/p\u003e\n"],["\u003cp\u003eIt provides three key pieces of information: an error code using \u003ccode\u003egoogle.rpc.Code\u003c/code\u003e, a developer-facing English error message, and optional error details for context.\u003c/p\u003e\n"],["\u003cp\u003eWhile logically represented by the \u003ccode\u003eStatus\u003c/code\u003e message, its actual implementation may vary across languages and wire protocols.\u003c/p\u003e\n"],["\u003cp\u003eThis error model can be utilized in diverse scenarios beyond APIs to ensure a uniform developer experience, including partial errors, workflow errors, batch operations, and asynchronous operations.\u003c/p\u003e\n"]]],["The `Status` message defines an error model with three data pieces: `code`, `message`, and `details`. The `code` is an error code, `message` is a developer-facing English error message, and `details` contains additional error information. This model can be used for partial, workflow, batch, and asynchronous operations and in logging. It is designed for simplicity and flexibility and is adaptable across different programming environments and API types, with a mapping system that can change based on implementation.\n"],null,["# Package google.rpc\n\nIndex\n-----\n\n- [Status](/assistant/sdk/reference/rpc/google.rpc#google.rpc.Status) (message)\n\nStatus\n------\n\nThe `Status` type defines a logical error model that is suitable for different programming environments, including REST APIs and RPC APIs. It is used by [gRPC](https://github.com/grpc). The error model is designed to be:\n\n- Simple to use and understand for most users\n- Flexible enough to meet unexpected needs\n\n#### Overview\n\nThe `Status` message contains three pieces of data: error code, error message, and error details. The error code should be an enum value of `google.rpc.Code`, but it may accept additional error codes if needed. The error message should be a developer-facing English message that helps developers *understand* and *resolve* the error. If a localized user-facing error message is needed, put the localized message in the error details or localize it in the client. The optional error details may contain arbitrary information about the error. There is a predefined set of error detail types in the package `google.rpc` that can be used for common error conditions.\n\n#### Language mapping\n\nThe `Status` message is the logical representation of the error model, but it is not necessarily the actual wire format. When the `Status` message is exposed in different client libraries and different wire protocols, it can be mapped differently. For example, it will likely be mapped to some exceptions in Java, but more likely mapped to some error codes in C.\n\n#### Other uses\n\nThe error model and the `Status` message can be used in a variety of environments, either with or without APIs, to provide a consistent developer experience across different environments.\n\nExample uses of this error model include:\n\n- Partial errors. If a service needs to return partial errors to the client, it may embed the `Status` in the normal response to indicate the partial errors.\n\n- Workflow errors. A typical workflow has multiple steps. Each step may have a `Status` message for error reporting.\n\n- Batch operations. If a client uses batch request and batch response, the `Status` message should be used directly inside batch response, one for each error sub-response.\n\n- Asynchronous operations. If an API call embeds asynchronous operation results in its response, the status of those operations should be represented directly using the `Status` message.\n\n- Logging. If some API errors are stored in logs, the message `Status` could be used directly after any stripping needed for security/privacy reasons.\n\n| Fields ||\n|-------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| `code` | `int32` The status code, which should be an enum value of `google.rpc.Code`. |\n| `message` | `string` A developer-facing error message, which should be in English. Any user-facing error message should be localized and sent in the [google.rpc.Status.details](/assistant/sdk/reference/rpc/google.rpc#google.rpc.Status.FIELDS.repeated.google.protobuf.Any.google.rpc.Status.details) field, or localized by the client. |\n| `details[]` | [Any](https://developers.google.com/protocol-buffers/docs/reference/google.protobuf#google.protobuf.Any) A list of messages that carry the error details. There is a common set of message types for APIs to use. |"]]