在 Fiddler for R httr 库中模拟 500 错误
Simulate 500 error in Fiddler for R httr library
我有闪亮的网络应用程序,我想测试我的代码是否有来自 API 的 500 个错误。我的应用程序正在使用 httr 库。我在 fiddler:
中设置了这个
static function OnBeforeResponse(oSession: Session) {
if (m_Hide304s && oSession.responseCode == 304) {
oSession["ui-hide"] = "true";
}
if (oSession.url.Contains("study.xml")) {
oSession.oResponse.headers.HTTPResponseCode = 500;
oSession.oResponse.headers.Add("Foo", "Bar");
}
}
在 R 代码中我有这个:
path <- paste0(
url,
"/study.xml/", .session$sid, "/analysis_data"
)
res <- GET(path, use_proxy("127.0.0.1", 8888))
print(paste(path, res$status_code))
print(json(headers(res)))
if (res$status_code == 500) {
# handler error
stop("error 500")
}
即使我在 Fiddler 中有 500 个响应,在 R 中我有 200 个,header 设置正确,当页面 return 404 我得到 404 响应。
还有其他方法可以在 fiddler 中模拟 500 错误代码吗?我发现 Fiddler 脚本最简单,因为我不需要 fiddle 使用 Fiddler 界面。
找到了,我需要使用:
oSession.oRequest.FailSession(500, "Blocked", "Fiddler blocked this request");
我有闪亮的网络应用程序,我想测试我的代码是否有来自 API 的 500 个错误。我的应用程序正在使用 httr 库。我在 fiddler:
中设置了这个static function OnBeforeResponse(oSession: Session) {
if (m_Hide304s && oSession.responseCode == 304) {
oSession["ui-hide"] = "true";
}
if (oSession.url.Contains("study.xml")) {
oSession.oResponse.headers.HTTPResponseCode = 500;
oSession.oResponse.headers.Add("Foo", "Bar");
}
}
在 R 代码中我有这个:
path <- paste0(
url,
"/study.xml/", .session$sid, "/analysis_data"
)
res <- GET(path, use_proxy("127.0.0.1", 8888))
print(paste(path, res$status_code))
print(json(headers(res)))
if (res$status_code == 500) {
# handler error
stop("error 500")
}
即使我在 Fiddler 中有 500 个响应,在 R 中我有 200 个,header 设置正确,当页面 return 404 我得到 404 响应。
还有其他方法可以在 fiddler 中模拟 500 错误代码吗?我发现 Fiddler 脚本最简单,因为我不需要 fiddle 使用 Fiddler 界面。
找到了,我需要使用:
oSession.oRequest.FailSession(500, "Blocked", "Fiddler blocked this request");