Skip to content

Commit

Permalink
Add ApiError back for backwards compat
Browse files Browse the repository at this point in the history
  • Loading branch information
Swimburger committed Jul 25, 2024
1 parent 5c6b681 commit a4f715c
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 37 deletions.
2 changes: 2 additions & 0 deletions .fernignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ src/main/java/com/assemblyai/api/PollingTranscriptsClient.java
src/main/java/com/assemblyai/api/Transcriber.java
src/main/java/com/assemblyai/api/RealtimeTranscriber.java
src/main/java/com/assemblyai/api/core/Constants.java
src/main/java/com/assemblyai/api/core/ApiError.java
src/main/java/com/assemblyai/api/core/AssemblyAIApiException.java

# Temporarily update deserialization logic
src/main/java/com/assemblyai/api/core/ObjectMappers.java
Expand Down
30 changes: 30 additions & 0 deletions sample-app/src/main/java/sample/App.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

import com.assemblyai.api.AssemblyAI;
import com.assemblyai.api.RealtimeTranscriber;
import com.assemblyai.api.core.ApiError;
import com.assemblyai.api.core.AssemblyAIApiException;
import com.assemblyai.api.core.AssemblyAIException;
import com.assemblyai.api.resources.files.types.UploadedFile;
import com.assemblyai.api.resources.lemur.requests.LemurQuestionAnswerParams;
import com.assemblyai.api.resources.lemur.requests.LemurTaskParams;
Expand Down Expand Up @@ -94,6 +97,33 @@ public static void main(String... args) throws IOException, InterruptedException
LemurQuestionAnswer qa2 = lemurQuestionAnswerResponse2.getResponse().get(0);
System.out.println("Q&A: " + qa2.getQuestion() + ": " + qa2.getAnswer());

try {
client.lemur().task(LemurTaskParams.builder().prompt("test").build());
} catch (AssemblyAIException e) {
System.out.println("Caught expected AssemblyAIException");
} catch (Exception e) {
System.err.println("Error: " + e.getMessage());
System.err.println("This error should've been AssemblyAIException, but is not.");
}

try {
client.lemur().task(LemurTaskParams.builder().prompt("test").build());
} catch (AssemblyAIApiException e) {
System.out.println("Caught expected AssemblyAIApiException");
} catch (Exception e) {
System.err.println("Error: " + e.getMessage());
System.err.println("This error should've been AssemblyAIApiException, but is not.");
}

try {
client.lemur().task(LemurTaskParams.builder().prompt("test").build());
} catch (ApiError e) {
System.out.println("Caught expected ApiError");
} catch (Exception e) {
System.err.println("Error: " + e.getMessage());
System.err.println("This error should've been ApiError, but is not.");
}

transcript = client.transcripts().delete(transcript.getId());
System.out.println("Delete transcript. " + transcript);

Expand Down
42 changes: 42 additions & 0 deletions src/main/java/com/assemblyai/api/core/ApiError.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package com.assemblyai.api.core;

/**
* This exception type will be thrown for any non-2XX API responses.
*/
public class ApiError extends AssemblyAIException {
/**
* The error code of the response that triggered the exception.
*/
private final int statusCode;

/**
* The body of the response that triggered the exception.
*/
private final Object body;

public ApiError(String message, int statusCode, Object body) {
super(message);
this.statusCode = statusCode;
this.body = body;
}

/**
* @return the statusCode
*/
public int statusCode() {
return this.statusCode;
}

/**
* @return the body
*/
public Object body() {
return this.body;
}

@java.lang.Override
public String toString() {
return "AssemblyAIApiException{" + "message: " + getMessage() + ", statusCode: " + statusCode + ", body: "
+ body + "}";
}
}
39 changes: 2 additions & 37 deletions src/main/java/com/assemblyai/api/core/AssemblyAIApiException.java
Original file line number Diff line number Diff line change
@@ -1,45 +1,10 @@
/**
* This file was auto-generated by Fern from our API Definition.
*/
package com.assemblyai.api.core;

/**
* This exception type will be thrown for any non-2XX API responses.
*/
public class AssemblyAIApiException extends AssemblyAIException {
/**
* The error code of the response that triggered the exception.
*/
private final int statusCode;

/**
* The body of the response that triggered the exception.
*/
private final Object body;

public class AssemblyAIApiException extends ApiError {
public AssemblyAIApiException(String message, int statusCode, Object body) {
super(message);
this.statusCode = statusCode;
this.body = body;
}

/**
* @return the statusCode
*/
public int statusCode() {
return this.statusCode;
}

/**
* @return the body
*/
public Object body() {
return this.body;
}

@java.lang.Override
public String toString() {
return "AssemblyAIApiException{" + "message: " + getMessage() + ", statusCode: " + statusCode + ", body: "
+ body + "}";
super(message, statusCode, body);
}
}

0 comments on commit a4f715c

Please sign in to comment.