mirror of
https://github.com/ossrs/srs.git
synced 2025-03-09 15:49:59 +00:00
refine the error response.
This commit is contained in:
parent
2edcf1d4ff
commit
20a8818a8e
2 changed files with 15 additions and 30 deletions
|
@ -509,31 +509,23 @@ int SrsGoApiStreams::serve_http(ISrsHttpResponseWriter* w, ISrsHttpMessage* r)
|
||||||
if (sid >= 0 && (stream = stat->find_stream(sid)) == NULL) {
|
if (sid >= 0 && (stream = stat->find_stream(sid)) == NULL) {
|
||||||
ret = ERROR_RTMP_STREAM_NOT_FOUND;
|
ret = ERROR_RTMP_STREAM_NOT_FOUND;
|
||||||
srs_error("stream stream_id=%d not found. ret=%d", sid, ret);
|
srs_error("stream stream_id=%d not found. ret=%d", sid, ret);
|
||||||
|
return srs_http_response_code(w, ret);
|
||||||
ss << SRS_JOBJECT_START
|
|
||||||
<< SRS_JFIELD_ERROR(ret)
|
|
||||||
<< SRS_JOBJECT_END;
|
|
||||||
|
|
||||||
return srs_http_response_json(w, ss.str());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (r->is_http_delete()) {
|
if (r->is_http_delete()) {
|
||||||
srs_assert(stream);
|
srs_assert(stream);
|
||||||
|
|
||||||
SrsSource* source = SrsSource::fetch(stream->vhost->vhost, stream->app, stream->stream);
|
SrsSource* source = SrsSource::fetch(stream->vhost->vhost, stream->app, stream->stream);
|
||||||
if (source) {
|
if (!source) {
|
||||||
|
ret = ERROR_SOURCE_NOT_FOUND;
|
||||||
|
srs_warn("source not found for sid=%d", sid);
|
||||||
|
return srs_http_response_code(w, ret);
|
||||||
|
}
|
||||||
|
|
||||||
source->set_expired();
|
source->set_expired();
|
||||||
srs_warn("disconnent stream=%d successfully. vhost=%s, app=%s, stream=%s.",
|
srs_warn("disconnent stream=%d successfully. vhost=%s, app=%s, stream=%s.",
|
||||||
sid, stream->vhost->vhost.c_str(), stream->app.c_str(), stream->stream.c_str());
|
sid, stream->vhost->vhost.c_str(), stream->app.c_str(), stream->stream.c_str());
|
||||||
} else {
|
return srs_http_response_code(w, ret);
|
||||||
ret = ERROR_SOURCE_NOT_FOUND;
|
|
||||||
}
|
|
||||||
|
|
||||||
ss << SRS_JOBJECT_START
|
|
||||||
<< SRS_JFIELD_ERROR(ret)
|
|
||||||
<< SRS_JOBJECT_END;
|
|
||||||
|
|
||||||
return srs_http_response_json(w, ss.str());
|
|
||||||
} else if (r->is_http_get()) {
|
} else if (r->is_http_get()) {
|
||||||
std::stringstream data;
|
std::stringstream data;
|
||||||
|
|
||||||
|
@ -584,10 +576,7 @@ int SrsGoApiClients::serve_http(ISrsHttpResponseWriter* w, ISrsHttpMessage* r)
|
||||||
if (cid >= 0 && (client = stat->find_client(cid)) == NULL) {
|
if (cid >= 0 && (client = stat->find_client(cid)) == NULL) {
|
||||||
ret = ERROR_RTMP_STREAM_NOT_FOUND;
|
ret = ERROR_RTMP_STREAM_NOT_FOUND;
|
||||||
srs_error("stream client_id=%d not found. ret=%d", cid, ret);
|
srs_error("stream client_id=%d not found. ret=%d", cid, ret);
|
||||||
|
return srs_http_response_code(w, ret);
|
||||||
ss << SRS_JOBJECT_START << SRS_JFIELD_ERROR(ret) << SRS_JOBJECT_END;
|
|
||||||
|
|
||||||
return srs_http_response_json(w, ss.str());
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -628,15 +617,7 @@ SrsGoApiError::~SrsGoApiError()
|
||||||
|
|
||||||
int SrsGoApiError::serve_http(ISrsHttpResponseWriter* w, ISrsHttpMessage* r)
|
int SrsGoApiError::serve_http(ISrsHttpResponseWriter* w, ISrsHttpMessage* r)
|
||||||
{
|
{
|
||||||
std::stringstream ss;
|
return srs_http_response_code(w, 100);
|
||||||
|
|
||||||
ss << SRS_JOBJECT_START
|
|
||||||
<< SRS_JFIELD_ERROR(100) << SRS_JFIELD_CONT
|
|
||||||
<< SRS_JFIELD_STR("msg", "SRS demo error.") << SRS_JFIELD_CONT
|
|
||||||
<< SRS_JFIELD_STR("path", r->path())
|
|
||||||
<< SRS_JOBJECT_END;
|
|
||||||
|
|
||||||
return srs_http_response_json(w, ss.str());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -78,6 +78,10 @@ class ISrsHttpResponseWriter;
|
||||||
|
|
||||||
// helper function: response in json format.
|
// helper function: response in json format.
|
||||||
extern int srs_http_response_json(ISrsHttpResponseWriter* w, std::string data);
|
extern int srs_http_response_json(ISrsHttpResponseWriter* w, std::string data);
|
||||||
|
/**
|
||||||
|
* response a typical code object, for example:
|
||||||
|
* {code : 100}
|
||||||
|
*/
|
||||||
extern int srs_http_response_code(ISrsHttpResponseWriter* w, int code);
|
extern int srs_http_response_code(ISrsHttpResponseWriter* w, int code);
|
||||||
|
|
||||||
// get the status text of code.
|
// get the status text of code.
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue