Skip to content

Commit 9554318

Browse files
committed
adding support for error endpoints
1 parent c78e4cb commit 9554318

File tree

3 files changed

+74
-0
lines changed

3 files changed

+74
-0
lines changed

src/main/java/com/algorithmia/algo/AlgorithmiaClient.java

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import com.algorithmia.data.DataDirectory;
66
import com.algorithmia.data.DataFile;
77
import com.google.gson.Gson;
8+
import org.apache.commons.io.IOExceptionList;
89
import org.apache.http.HttpResponse;
910
import org.apache.http.entity.ContentType;
1011
import org.apache.http.entity.StringEntity;
@@ -221,6 +222,33 @@ public BuildLogs getAlgoBuildLogs(String userName, String algoName, String build
221222
return gson.fromJson(responseString, BuildLogs.class);
222223
}
223224

225+
public ErrorLogs[] getUserErrors(String userName) throws IOException {
226+
String path = "/v1/users/"+ userName +"/errors";
227+
HttpResponse response = this.client.get(path);
228+
String responseString = EntityUtils.toString(response.getEntity());
229+
Gson gson = new Gson();
230+
ErrorLogs[] logs = gson.fromJson(responseString,ErrorLogs[].class);
231+
return logs;
232+
}
233+
234+
public ErrorLogs[] getAlgorithmErrors(String algoName) throws IOException {
235+
String path = "/v1/algorithms/"+algoName+"/errors";
236+
HttpResponse response = this.client.get(path);
237+
String responseString = EntityUtils.toString(response.getEntity());
238+
Gson gson = new Gson();
239+
ErrorLogs[] logs = gson.fromJson(responseString,ErrorLogs[].class);
240+
return logs;
241+
}
242+
243+
public ErrorLogs[] getOrganizationErrors(String orgName) throws IOException {
244+
String path = "/v1/organizations/"+orgName+"/errors";
245+
HttpResponse response = this.client.get(path);
246+
String responseString = EntityUtils.toString(response.getEntity());
247+
Gson gson = new Gson();
248+
ErrorLogs[] logs = gson.fromJson(responseString,ErrorLogs[].class);
249+
return logs;
250+
}
251+
224252
/**
225253
* Create a new Algorithm object from this client
226254
*
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package com.algorithmia.algo;
2+
3+
import com.google.gson.annotations.SerializedName;
4+
import lombok.AllArgsConstructor;
5+
import lombok.Getter;
6+
import lombok.NoArgsConstructor;
7+
import lombok.Setter;
8+
9+
@NoArgsConstructor
10+
@AllArgsConstructor
11+
@Setter
12+
@Getter
13+
public class ErrorLogs {
14+
@SerializedName("created_at")
15+
private String createdAt;
16+
@SerializedName("request_id")
17+
private String requestId;
18+
private String username;
19+
private String algoname;
20+
private String algoversion;
21+
private String input;
22+
private String error;
23+
@SerializedName("error_type")
24+
private String errorType;
25+
@SerializedName("billable_to")
26+
private String billableTo;
27+
private String worker;
28+
}

src/test/java/com/algorithmia/algo/AlgorithmTest.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,24 @@ public void algoGetAlgoBuildLogs() throws Exception {
270270
Assert.assertNotNull(buildLogs.getLogs());
271271
}
272272

273+
@Test
274+
public void algoGetUserErrorLogs() throws Exception {
275+
ErrorLogs errorlogs[] = Algorithmia.client(defaultKey).getUserErrors("J_Bragg2");
276+
Assert.assertNotNull(errorlogs[0].getCreatedAt());
277+
}
278+
279+
@Test
280+
public void algoGetAlgorithmErrorLogs() throws Exception {
281+
ErrorLogs errorlogs[] = Algorithmia.client(defaultKey).getAlgorithmErrors("J_Bragg2/Echo");
282+
Assert.assertNotNull(errorlogs[0].getCreatedAt());
283+
}
284+
285+
@Test
286+
public void algoGetOrgErrorLogs() throws Exception {
287+
ErrorLogs errorlogs[] = Algorithmia.client(defaultKey).getOrganizationErrors("J_Bragg2");
288+
Assert.assertNotNull(errorlogs[0].getCreatedAt());
289+
}
290+
273291
@Test
274292
public void algoDeleteAlgo() throws Exception {
275293
Algorithm testAlgo = createTestAlgo();

0 commit comments

Comments
 (0)