HTTP Status Code for External Dependency Error

前端 未结 3 955
忘掉有多难
忘掉有多难 2021-02-05 01:45

What is the correct HTTP status code to return when a server is having issues communicating with an external API?

Say a client sends a valid request to my server A, A th

3条回答
  •  忘了有多久
    2021-02-05 02:15

    Did you consider status codes 502 and 504?

    502 – The server while acting as a gateway or a proxy, 
    received an invalid response from the upstream server it accessed
    in attempting to fulfill the request.
    
    504 – The server, while acting as a gateway or proxy, 
    did not receive a timely response from the upstream server 
    specified by the URI (e.g. HTTP, FTP, LDAP) 
    or some other auxiliary server (e.g. DNS) it needed to access 
    in attempting to complete the request.
    

    Of course, this would require a broad interpretation of "gateway" (implementation of interface A requiring a call to interface B), applied to the application layer. But this could be a nice way to say : "I cannot answer but it's not my fault nor yours".

提交回复
热议问题