gRPC

Giả lập phản hồi 4 DEADLINE_EXCEEDED

The deadline expired before the operation could complete. For operations that change the state of the system, this error may be returned even if the operation has completed successfully.

Xem tài liệu tham khảo đầy đủ →

1 Phản hồi HTTP

Phản hồi HTTP
HTTP/1.1 4 DEADLINE_EXCEEDED
Content-Type: application/json
Date: Tue, 25 Feb 2026 12:00:00 GMT
Content-Length: 62

{
  "error": "deadline_exceeded",
  "message": "DEADLINE_EXCEEDED"
}

2 Kiểm tra với curl

terminal
curl -i https://httpbin.org/status/4

3 Trả về 4 DEADLINE_EXCEEDED trong Framework của bạn

django
from django.http import JsonResponse


def my_view(request):
    return JsonResponse(
        {"error": "deadline_exceeded", "message": "DEADLINE_EXCEEDED"},
        status=4,
    )
flask
from flask import Flask, jsonify

app = Flask(__name__)


@app.route("/endpoint")
def my_endpoint():
    return jsonify({"error": "deadline_exceeded", "message": "DEADLINE_EXCEEDED"}), 4
fastapi
from fastapi import FastAPI
from fastapi.responses import JSONResponse

app = FastAPI()


@app.get("/endpoint")
def my_endpoint():
    return JSONResponse(
        content={"error": "deadline_exceeded", "message": "DEADLINE_EXCEEDED"},
        status_code=4,
    )
express.js
// Express.js
app.get('/endpoint', (req, res) => {
  res.status(4).json({"error": "deadline_exceeded", "message": "DEADLINE_EXCEEDED"});
});
spring boot
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import java.util.Map;

@RestController
public class MyController {

    @GetMapping("/endpoint")
    public ResponseEntity<Map<String, Object>> myEndpoint() {
        return ResponseEntity
            .status(4)
            .body(Map.of("error", "deadline_exceeded",
                         "message", "DEADLINE_EXCEEDED"));
    }
}
go net/http
package main

import (
    "encoding/json"
    "net/http"
)

func myHandler(w http.ResponseWriter, r *http.Request) {
    w.Header().Set("Content-Type", "application/json")
    w.WriteHeader(4)
    json.NewEncoder(w).Encode(map[string]string{
        "error":   "deadline_exceeded",
        "message": "DEADLINE_EXCEEDED",
    })
}
ruby on rails
class MyController < ApplicationController
  def my_action
    render json: {"error": "deadline_exceeded", "message": "DEADLINE_EXCEEDED"},
           status: :deadline_exceeded
  end
end
asp.net core
// ASP.NET Core Minimal API
app.MapGet("/endpoint", () =>
    Results.Json(
        new { error = "deadline_exceeded", message = "DEADLINE_EXCEEDED" },
        statusCode: 4
    )
);

Thêm trang giả lập gRPC