简体   繁体   English

c#api status:如果我们从处理api请求所需的某些中间服务获得空响应,应该是什么状态和异常

[英]c# api status: what should be status and exception if we get null response from some intermediate service required to process api request

We have an API that sends SMS to the users. 我们有一个API,可以将SMS发送给用户。 In the SMS content, we need to send the tinyUrl.We have external service that return us the shortUrl ie 在SMS内容中,我们需要发送tinyUrl。我们拥有外部服务,该服务会向我们返回shortUrl,即

string shortUrl = UrlShortenerService.GetShortUrl(longUrl);

What should be status code returned to the client if I get null shortUrl from this service response. 如果我从此服务响应中得到null shortUrl,应该返回给客户端的状态代码是什么。 What should be the exception type? 异常类型应该是什么?

The API is not just responsible to send the shortUrl but to send this shortUrl to user's mobile so we can't return 2xx status as the request was not fulfilled, we can't send 4xx request as there was nothing wrong in client's request. API不仅负责发送shortUrl,还负责将此shortUrl发送到用户的移动设备,因此由于请求未得到满足,我们无法返回2xx状态,而由于客户的请求没有错,我们也无法发送4xx请求。

you can use a 503. It's an error caused by the external service. 您可以使用503。这是由外部服务引起的错误。 Or if you want to be more general you can use the 500 status code 或者,如果您想更一般一些,可以使用500状态代码

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM