Skip to content

Commit

Permalink
Fixed error handling issue
Browse files Browse the repository at this point in the history
  • Loading branch information
gonz authored Dec 8, 2017
2 parents 8ed1160 + e1ef5b5 commit 4329ec9
Showing 1 changed file with 35 additions and 13 deletions.
48 changes: 35 additions & 13 deletions src/Classification.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,9 @@ function classify($module_id, $sample_list, $sandbox=false,
} else {
$data = array('text_list' => $batch);
}

try{
list($response, $header) = $this->make_request($url, 'POST', $data, $sleep_if_throttled);
} catch (\MonkeyLearnException $mle){ throw $mle;}
$headers[] = $header;
$res = array_merge($res, $response['result']);
}
Expand All @@ -41,13 +42,17 @@ function classify($module_id, $sample_list, $sandbox=false,

function list_classifiers($sleep_if_throttled=true) {
$url = $this->endpoint;
list($response, $header) = $this->make_request($url, 'GET', null, $sleep_if_throttled);
try{
list($response, $header) = $this->make_request($url, 'GET', null, $sleep_if_throttled);
} catch (\MonkeyLearnException $mle){ throw $mle;}
return new MonkeyLearnResponse($response['result'], array($header));
}

function detail($module_id, $sleep_if_throttled=true) {
$url = $this->endpoint.$module_id;
list($response, $header) = $this->make_request($url, 'GET', null, $sleep_if_throttled);
try{
list($response, $header) = $this->make_request($url, 'GET', null, $sleep_if_throttled);
} catch (\MonkeyLearnException $mle){ throw $mle;}
return new MonkeyLearnResponse($response['result'], array($header));
}

Expand Down Expand Up @@ -81,26 +86,33 @@ function upload_samples($module_id, $samples_with_categories, $sleep_if_throttle
if ($features_schema) {
$data['features_schema'] = $features_schema;
}

list($response, $header) = $this->make_request($url, 'POST', $data, $sleep_if_throttled);
try {
list($response, $header) = $this->make_request($url, 'POST', $data, $sleep_if_throttled);
} catch (\MonkeyLearnException $mle){ throw $mle;}
return new MonkeyLearnResponse($response['result'], array($header));
}

function train($module_id, $sleep_if_throttled=true) {
$url = $this->endpoint.$module_id.'/train/';
list($response, $header) = $this->make_request($url, 'POST', null, $sleep_if_throttled);
try{
list($response, $header) = $this->make_request($url, 'POST', null, $sleep_if_throttled);
} catch (\MonkeyLearnException $mle){ throw $mle;}
return new MonkeyLearnResponse($response['result'], array($header));
}

function deploy($module_id, $sleep_if_throttled=true) {
$url = $this->endpoint.$module_id.'/deploy/';
list($response, $header) = $this->make_request($url, 'POST', null, $sleep_if_throttled);
try{
list($response, $header) = $this->make_request($url, 'POST', null, $sleep_if_throttled);
} catch (\MonkeyLearnException $mle){ throw $mle;}
return new MonkeyLearnResponse($response['result'], array($header));
}

function delete($module_id, $sleep_if_throttled=true) {
$url = $this->endpoint.$module_id;
list($response, $header) = $this->make_request($url, 'DELETE', null, $sleep_if_throttled);
try{
list($response, $header) = $this->make_request($url, 'DELETE', null, $sleep_if_throttled);
} catch (\MonkeyLearnException $mle){ throw $mle;}
return new MonkeyLearnResponse($response['result'], array($header));
}

Expand Down Expand Up @@ -137,7 +149,9 @@ function create($name, $description=null, $train_state=null, $language=null, $ng
}

$url = $this->endpoint;
list($response, $header) = $this->make_request($url, 'POST', $data, $sleep_if_throttled);
try{
list($response, $header) = $this->make_request($url, 'POST', $data, $sleep_if_throttled);
} catch (\MonkeyLearnException $mle){ throw $mle;}
return new MonkeyLearnResponse($response['result'], array($header));
}
}
Expand All @@ -150,7 +164,9 @@ function __construct($token, $base_endpoint) {

function detail($module_id, $category_id, $sleep_if_throttled=true) {
$url = $this->endpoint.$module_id.'/categories/'.$category_id.'/';
list($response, $header) = $this->make_request($url, 'GET', null, $sleep_if_throttled);
try{
list($response, $header) = $this->make_request($url, 'GET', null, $sleep_if_throttled);
} catch (\MonkeyLearnException $mle){ throw $mle;}
return new MonkeyLearnResponse($response['result'], array($header));
}

Expand All @@ -162,7 +178,9 @@ function create($module_id, $name, $parent_id, $sleep_if_throttled=true) {
);

$url = $this->endpoint.$module_id.'/categories/';
list($response, $header) = $this->make_request($url, 'POST', $data, $sleep_if_throttled);
try{
list($response, $header) = $this->make_request($url, 'POST', $data, $sleep_if_throttled);
} catch (\MonkeyLearnException $mle){ throw $mle;}
return new MonkeyLearnResponse($response['result'], array($header));
}

Expand All @@ -181,7 +199,9 @@ function edit($module_id, $category_id, $name=null, $parent_id=null,
}

$url = $this->endpoint.$module_id.'/categories/'.$category_id.'/';
list($response, $header) = $this->make_request($url, 'PATCH', $data, $sleep_if_throttled);
try{
list($response, $header) = $this->make_request($url, 'PATCH', $data, $sleep_if_throttled);
} catch (\MonkeyLearnException $mle){ throw $mle;}
return new MonkeyLearnResponse($response['result'], array($header));
}

Expand All @@ -200,7 +220,9 @@ function delete($module_id, $category_id, $samples_strategy=null,
}

$url = $this->endpoint.$module_id.'/categories/'.$category_id.'/';
list($response, $header) = $this->make_request($url, 'DELETE', $data, $sleep_if_throttled);
try{
list($response, $header) = $this->make_request($url, 'DELETE', $data, $sleep_if_throttled);
} catch (\MonkeyLearnException $mle){ throw $mle;}
return new MonkeyLearnResponse($response['result'], array($header));
}
}
Expand Down

0 comments on commit 4329ec9

Please sign in to comment.