简体   繁体   English

进行SMTP连接测试的REST API发生故障时的HTTP状态代码

[英]HTTP status code in case of failure scenario for a REST API which does SMTP connection test

What should be right http status code which we should use in REST response for an API which does SMTP configuration test and send test mail for failure scenario like SMTP configuration is not correct or Authentication Issue with smtp server etc. 应该正确的http状态代码,我们应该在REST响应中使用API​​进行SMTP配置测试并针对SMTP配置失败情况发送测试邮件,例如SMTP配置不正确或smtp服务器的身份验证问题等。

Any suggestions. 有什么建议么。

I would suggest returning 200 OK with a message about failure in response body or header. 我建议返回200 OK,并带有有关响应正文或标头失败的消息。 If you put it 400 (BAD_REQUEST) or some other error code, you wouldn't know if the service was down or there was something else wrong with the code, which caused the bad response. 如果将其设置为400(BAD_REQUEST)或其他错误代码,您将不知道服务是否关闭或该代码是否存在其他错误,从而导致响应错误。

If you do want to check the service availability, I'd suggest 417 (expectation failed) 如果您确实要检查服务的可用性,建议您输入417(预期失败)

Not a big expert of SMTP but I would suggest you to google for the list of SMTP status and then map those SMTP status to HTTP status code . 不是SMTP的专家,但我建议您用谷歌搜索SMTP状态列表,然后将这些SMTP状态映射到HTTP状态代码 Most of the time for HTTP status, you have 3 main categories grouped by status code (ranges): 在大多数情况下,HTTP状态中,您有3个主要类别,按状态代码(范围)分组:

  • 200 for good execution 200执行力
  • 400 for user errors 400个用户错误
  • 500 for server errors 服务器错误为500

I don't really know if there is a relation between SMTP and HTTP code status. 我真的不知道SMTP和HTTP代码状态之间是否存在关系。 In this case it is your own choice to choose which status code you will map together, and then return the good HTTP code result. 在这种情况下,您可以选择要一起映射的状态代码,然后返回良好的HTTP代码结果。

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

相关问题 REST API - HTTP 文件上传,状态码为 415 - REST API - HTTP Fileupload with Status Code 415 Rest API:HTTP 信息性消息的状态代码 - Rest API: HTTP Status code for Informational Message 如果在 Rest Api 调用中没有从数据库中找到数据,则返回哪个 HTTP 状态码 - Which HTTP status code to return if there is no data found from database in Rest Api call HTTP状态代码500是否表示未出现其余错误代码 - Does HTTP Status Code 500 means that the rest error code are not occuring 如何自定义 Spring-Security 中的 http 状态码以应对特殊情况认证失败? - How can I customize the http status code in Spring-Security for a special case authentication failure? 在部分失败的情况下进行REST API设计 - Rest API Design in case of partial failure Spring类AuthenticationProvider中如何在403 http状态的情况下拦截来自REST API的响应 - How to intercept the response from REST API in case of 403 http status, in Spring class AuthenticationProvider 如何使用REST API在ALM中更新测试用例的状态 - How can I update a status for test case in ALM using REST API 使用放心的 junit 测试用例拒绝连接 - Connection refused with rest assured junit test case 使用Rest Assured Get类型返回400状态代码的测试REST API - Test REST API using Rest Assured Get type returning 400 status code
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM