mirror of
https://github.com/jambonz/freeswitch-modules.git
synced 2025-12-19 08:27:44 +00:00
Add Error Code Check to Google V1 Implementation (#51)
* Put the check for `grpc` error code 0 in the Google Speech-To-Text v1 as well. * Distinguish between two types of error object in `grpc_read_thread` * Improve naming of JSON field * Correct error in JSON field name. * Add sign-off to previous commit Signed-off-by: Andrew Golledge <andreas.golledge@gmail.com> --------- Signed-off-by: Andrew Golledge <andreas.golledge@gmail.com>
This commit is contained in:
@@ -236,6 +236,7 @@ static void *SWITCH_THREAD_FUNC grpc_read_thread(switch_thread_t *thread, void *
|
|||||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "grpc_read_thread: error %s (%d)\n", status.message().c_str(), status.code()) ;
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "grpc_read_thread: error %s (%d)\n", status.message().c_str(), status.code()) ;
|
||||||
cJSON* json = cJSON_CreateObject();
|
cJSON* json = cJSON_CreateObject();
|
||||||
cJSON_AddStringToObject(json, "type", "error");
|
cJSON_AddStringToObject(json, "type", "error");
|
||||||
|
cJSON_AddStringToObject(json, "error_cause", "stream_response");
|
||||||
cJSON_AddStringToObject(json, "error", status.message().c_str());
|
cJSON_AddStringToObject(json, "error", status.message().c_str());
|
||||||
char* jsonString = cJSON_PrintUnformatted(json);
|
char* jsonString = cJSON_PrintUnformatted(json);
|
||||||
cb->responseHandler(session, jsonString, cb->bugname);
|
cb->responseHandler(session, jsonString, cb->bugname);
|
||||||
@@ -339,9 +340,10 @@ static void *SWITCH_THREAD_FUNC grpc_read_thread(switch_thread_t *thread, void *
|
|||||||
cb->responseHandler(session, "no_audio", cb->bugname);
|
cb->responseHandler(session, "no_audio", cb->bugname);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else if (status.error_code() != 0) {
|
||||||
cJSON* json = cJSON_CreateObject();
|
cJSON* json = cJSON_CreateObject();
|
||||||
cJSON_AddStringToObject(json, "type", "error");
|
cJSON_AddStringToObject(json, "type", "error");
|
||||||
|
cJSON_AddStringToObject(json, "error_cause", "stream_close");
|
||||||
cJSON_AddItemToObject(json, "error_code", cJSON_CreateNumber(status.error_code()));
|
cJSON_AddItemToObject(json, "error_code", cJSON_CreateNumber(status.error_code()));
|
||||||
cJSON_AddStringToObject(json, "error_message", status.error_message().c_str());
|
cJSON_AddStringToObject(json, "error_message", status.error_message().c_str());
|
||||||
char* jsonString = cJSON_PrintUnformatted(json);
|
char* jsonString = cJSON_PrintUnformatted(json);
|
||||||
|
|||||||
@@ -349,6 +349,7 @@ static void *SWITCH_THREAD_FUNC grpc_read_thread(switch_thread_t *thread, void *
|
|||||||
else if (status.error_code() != 0) {
|
else if (status.error_code() != 0) {
|
||||||
cJSON* json = cJSON_CreateObject();
|
cJSON* json = cJSON_CreateObject();
|
||||||
cJSON_AddStringToObject(json, "type", "error");
|
cJSON_AddStringToObject(json, "type", "error");
|
||||||
|
cJSON_AddStringToObject(json, "error_cause", "stream_close");
|
||||||
cJSON_AddItemToObject(json, "error_code", cJSON_CreateNumber(status.error_code()));
|
cJSON_AddItemToObject(json, "error_code", cJSON_CreateNumber(status.error_code()));
|
||||||
cJSON_AddStringToObject(json, "error_message", status.error_message().c_str());
|
cJSON_AddStringToObject(json, "error_message", status.error_message().c_str());
|
||||||
char* jsonString = cJSON_PrintUnformatted(json);
|
char* jsonString = cJSON_PrintUnformatted(json);
|
||||||
|
|||||||
Reference in New Issue
Block a user