Skip to content

Commit

Permalink
fix error messages - process timeout to 14sec
Browse files Browse the repository at this point in the history
  • Loading branch information
xribene committed Nov 11, 2024
1 parent 9ff844b commit c2c7bab
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 6 deletions.
5 changes: 3 additions & 2 deletions src/WebModel.h
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,8 @@ class WebModel : public Model
}

juce::String response;
result = gradioClient.getResponseFromEventID(endpoint, eventId, response);
result =
gradioClient.getResponseFromEventID(endpoint, eventId, response, 14000);
if (result.failed())
{
status2 = ModelStatus::ERROR;
Expand All @@ -244,7 +245,7 @@ class WebModel : public Model
juce::JSON::parse(responseData, parsedData);
if (! parsedData.isObject())
{
error.devMessage = "Failed to parse the data portion of the received controls JSON.";
error.devMessage = "Failed to parse the 'data' key of the received JSON.";
status2 = ModelStatus::ERROR;
return OpResult::fail(error);
}
Expand Down
14 changes: 14 additions & 0 deletions src/errors.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,16 @@ enum class ErrorType
struct Error
{
ErrorType type;
int code = -1;
juce::String devMessage;
juce::String userMessage;

/*
* In this function, we parse the detailed developer message
* of an Error object, and fill the user message accordingly.
* by default, we set the user message to the developer message.
* TODO: the if/else statements below are very simple checks, and
* serve just as an example.
*/
static void fillUserMessage(Error& error)
{
Expand All @@ -51,6 +54,17 @@ struct Error
{
error.userMessage = "TIMEOUT: The gradio app is SLEEPING. Please try again later.";
}
else if (containsAllSubstrings(error.devMessage, { "GET", "input stream" }))
{
//
error.userMessage = error.devMessage;
// error.userMessage += "\n There was some network connectivity issue. Please try again";
if (error.code == 0)
{
error.userMessage +=
"\n\nProbably a request timeout, e.g the model is taking too long to process the audio file.";
}
}
}
else if (error.type == ErrorType::FileUploadError)
{
Expand Down
9 changes: 6 additions & 3 deletions src/gradio/GradioClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@ OpResult GradioClient::extractKeyFromResponse(const juce::String& response,
{
Error error;
error.type = ErrorType::MissingJsonKey;
error.devMessage = "Key " + key + " not found in response";
error.userMessage = error.devMessage;
error.devMessage = "Missing Key in JSON :: Key " + key + " not found in response";
return OpResult::fail(error);
}

Expand Down Expand Up @@ -209,6 +208,7 @@ OpResult GradioClient::uploadFileRequest(const juce::File& fileToUpload,

if (stream == nullptr)
{
error.code = statusCode;
error.devMessage = "Failed to create input stream for file upload request.";
return OpResult::fail(error);
}
Expand Down Expand Up @@ -281,6 +281,7 @@ OpResult GradioClient::makePostRequestForEventID(const juce::String endpoint,

if (stream == nullptr)
{
error.code = statusCode;
error.devMessage = "Failed to create input stream for POST request to " + endpoint;
return OpResult::fail(error);
}
Expand All @@ -290,6 +291,7 @@ OpResult GradioClient::makePostRequestForEventID(const juce::String endpoint,
// Check the status code to ensure the request was successful
if (statusCode != 200)
{
error.code = statusCode;
error.devMessage =
"Request to " + endpoint + " failed with status code: " + juce::String(statusCode);
return OpResult::fail(error);
Expand Down Expand Up @@ -350,8 +352,9 @@ OpResult GradioClient::getResponseFromEventID(const juce::String callID,

if (stream == nullptr)
{
error.code = statusCode;
error.devMessage =
"Failed to create input stream for GET request to " + callID + "/" + eventID;
"Failed to create input stream for GET request \nto " + callID + "/" + eventID;
return OpResult::fail(error);
}

Expand Down
2 changes: 1 addition & 1 deletion src/media/MidiDisplayComponent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ MidiDisplayComponent::MidiDisplayComponent()
addAndMakeVisible(pianoRoll);

mediaHandlerInstructions =
"MIDI pianoroll.\nClick and drag to start playback from any point in the pianoroll\nVertical scroll to zoom in/out.\nHorizontal scroll to move the pianoroll.";
"MIDI pianoroll.\nClick and drag to start playback from any point in the pianoroll\nVertical or Horizontal scroll to move.\nCmd+scroll to zoom in both axis.";
}

MidiDisplayComponent::~MidiDisplayComponent()
Expand Down

0 comments on commit c2c7bab

Please sign in to comment.