Skip to content

Error Codes

GameSO API ใช้ HTTP status codes มาตรฐาน และส่ง error response ในรูปแบบ JSON

Error Response Format

json
{
    "status": 400,
    "code": "BAD_REQUEST",
    "message": "reference_id is required"
}
FieldTypeDescription
statusintegerHTTP status code
codestringError code สำหรับ programmatic handling
messagestringรายละเอียดข้อผิดพลาดที่อ่านได้

HTTP Status Codes

Statusความหมาย
200สำเร็จ
400Bad Request — ข้อมูลที่ส่งมาไม่ถูกต้อง
401Unauthorized — API Key ไม่ถูกต้องหรือไม่ได้ส่งมา
404Not Found — ไม่พบ resource ที่ขอ
409Conflict — ข้อมูลซ้ำ เช่น reference_id ซ้ำ
503Service Unavailable — ยอดเงินไม่เพียงพอหรือระบบมีปัญหา

Error Codes

400 Bad Request

Codeสาเหตุวิธีแก้
BAD_REQUESTข้อมูลที่ส่งมาไม่ครบหรือไม่ถูกต้องตรวจสอบ request body
VALIDATION_ERRORข้อมูลไม่ผ่าน validationดู message สำหรับรายละเอียด
INVALID_SKUSKU ไม่ถูกต้องหรือไม่มีในระบบตรวจสอบ SKU ที่ใช้

401 Unauthorized

Codeสาเหตุวิธีแก้
UNAUTHORIZEDไม่มี API Key หรือ Key ไม่ถูกต้องตรวจสอบ X-API-Key header

404 Not Found

Codeสาเหตุวิธีแก้
NOT_FOUNDไม่พบ order ที่ขอตรวจสอบ reference_id

409 Conflict

Codeสาเหตุวิธีแก้
DUPLICATE_REFERENCEreference_id ซ้ำกับ order ที่มีอยู่แล้วใช้ reference_id ใหม่ หรือ query order เดิม

503 Service Unavailable

Codeสาเหตุวิธีแก้
INSUFFICIENT_BALANCEยอดเงินในกระเป๋าไม่เพียงพอเติมเงินในกระเป๋าก่อน
SERVICE_UNAVAILABLEระบบมีปัญหาชั่วคราวลองใหม่ภายหลัง

ตัวอย่าง Error Handling

javascript
async function createOrder(orderData) {
    const response = await fetch("https://api.gameso.io/v1/orders", {
        method: "POST",
        headers: {
            "Content-Type": "application/json",
            "X-API-Key": process.env.GAMESO_API_KEY,
        },
        body: JSON.stringify(orderData),
    });

    if (!response.ok) {
        const error = await response.json();

        switch (error.code) {
            case "DUPLICATE_REFERENCE":
                // reference_id ซ้ำ — ดึง order เดิมมาแทน
                return getOrder(orderData.reference_id);

            case "INSUFFICIENT_BALANCE":
                throw new Error("กระเป๋าเงินไม่เพียงพอ กรุณาเติมเงินก่อน");

            case "UNAUTHORIZED":
                throw new Error("API Key ไม่ถูกต้อง");

            default:
                throw new Error(`API Error: ${error.message}`);
        }
    }

    return response.json();
}

GameSO API Documentation