Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions .fern/metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@
"generatorVersion": "4.0.4",
"generatorConfig": {
"package-prefix": "com.deepgram",
"base-api-exception-class-name": "DeepgramApiException",
"enable-forward-compatible-enums": true,
"client": {
"class-name": "DeepgramClient"
},
"enable-wire-tests": true
},
"originGitCommit": "78fd4d4c60752a78daaa68b3d58da0554c9ce481",
"sdkVersion": "0.1.0"
"originGitCommit": "aa80de0e6348f76fb3fbb9cb17fdbe613222dd13",
"sdkVersion": "0.1.1"
}
6 changes: 3 additions & 3 deletions src/main/java/com/deepgram/core/ClientOptions.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,10 @@ private ClientOptions(
this.headers.putAll(headers);
this.headers.putAll(new HashMap<String, String>() {
{
put("User-Agent", "com.deepgram:deepgram-java-sdk/0.1.0");
put("User-Agent", "com.deepgram:deepgram-sdk/0.1.1");
put("X-Fern-Language", "JAVA");
put("X-Fern-SDK-Name", "com.deepgram:deepgram-java-sdk");
put("X-Fern-SDK-Version", "0.1.0");
put("X-Fern-SDK-Name", "com.deepgram.fern:api-sdk");
put("X-Fern-SDK-Version", "0.1.1");
}
});
this.headerSuppliers = headerSuppliers;
Expand Down
73 changes: 0 additions & 73 deletions src/main/java/com/deepgram/core/DeepgramApiApiException.java

This file was deleted.

66 changes: 61 additions & 5 deletions src/main/java/com/deepgram/core/DeepgramApiException.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,71 @@
*/
package com.deepgram.core;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import okhttp3.Response;

/**
* This class serves as the base exception for all errors in the SDK.
* This exception type will be thrown for any non-2XX API responses.
*/
public class DeepgramApiException extends RuntimeException {
public DeepgramApiException(String message) {
public class DeepgramApiException extends DeepgramApiException {
/**
* 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;

private final Map<String, List<String>> headers;

public DeepgramApiException(String message, int statusCode, Object body) {
super(message);
this.statusCode = statusCode;
this.body = body;
this.headers = new HashMap<>();
}

public DeepgramApiException(String message, int statusCode, Object body, Response rawResponse) {
super(message);
this.statusCode = statusCode;
this.body = body;
this.headers = new HashMap<>();
rawResponse.headers().forEach(header -> {
String key = header.component1();
String value = header.component2();
this.headers.computeIfAbsent(key, _str -> new ArrayList<>()).add(value);
});
}

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

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

/**
* @return the headers
*/
public Map<String, List<String>> headers() {
return this.headers;
}

public DeepgramApiException(String message, Exception e) {
super(message, e);
@Override
public String toString() {
return "DeepgramApiException{" + "message: " + getMessage() + ", statusCode: " + statusCode + ", body: "
+ ObjectMappers.stringify(body) + "}";
}
}
4 changes: 2 additions & 2 deletions src/main/java/com/deepgram/errors/BadRequestError.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
*/
package com.deepgram.errors;

import com.deepgram.core.DeepgramApiApiException;
import com.deepgram.core.DeepgramApiException;
import okhttp3.Response;

public final class BadRequestError extends DeepgramApiApiException {
public final class BadRequestError extends DeepgramApiException {
/**
* The body of the response that triggered the exception.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
package com.deepgram.resources.agent.v1.settings.think.models;

import com.deepgram.core.ClientOptions;
import com.deepgram.core.DeepgramApiApiException;
import com.deepgram.core.DeepgramApiException;
import com.deepgram.core.DeepgramApiHttpResponse;
import com.deepgram.core.ObjectMappers;
Expand Down Expand Up @@ -83,7 +82,7 @@ public void onResponse(@NotNull Call call, @NotNull Response response) throws IO
// unable to map error response, throwing generic error
}
Object errorBody = ObjectMappers.parseErrorBody(responseBodyString);
future.completeExceptionally(new DeepgramApiApiException(
future.completeExceptionally(new DeepgramApiException(
"Error with status code " + response.code(), response.code(), errorBody, response));
return;
} catch (IOException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
package com.deepgram.resources.agent.v1.settings.think.models;

import com.deepgram.core.ClientOptions;
import com.deepgram.core.DeepgramApiApiException;
import com.deepgram.core.DeepgramApiException;
import com.deepgram.core.DeepgramApiHttpResponse;
import com.deepgram.core.ObjectMappers;
Expand Down Expand Up @@ -73,7 +72,7 @@ public DeepgramApiHttpResponse<AgentThinkModelsV1Response> list(RequestOptions r
// unable to map error response, throwing generic error
}
Object errorBody = ObjectMappers.parseErrorBody(responseBodyString);
throw new DeepgramApiApiException(
throw new DeepgramApiException(
"Error with status code " + response.code(), response.code(), errorBody, response);
} catch (IOException e) {
throw new DeepgramApiException("Network error executing HTTP request", e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
package com.deepgram.resources.auth.v1.tokens;

import com.deepgram.core.ClientOptions;
import com.deepgram.core.DeepgramApiApiException;
import com.deepgram.core.DeepgramApiException;
import com.deepgram.core.DeepgramApiHttpResponse;
import com.deepgram.core.MediaTypes;
Expand Down Expand Up @@ -108,7 +107,7 @@ public void onResponse(@NotNull Call call, @NotNull Response response) throws IO
// unable to map error response, throwing generic error
}
Object errorBody = ObjectMappers.parseErrorBody(responseBodyString);
future.completeExceptionally(new DeepgramApiApiException(
future.completeExceptionally(new DeepgramApiException(
"Error with status code " + response.code(), response.code(), errorBody, response));
return;
} catch (IOException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
package com.deepgram.resources.auth.v1.tokens;

import com.deepgram.core.ClientOptions;
import com.deepgram.core.DeepgramApiApiException;
import com.deepgram.core.DeepgramApiException;
import com.deepgram.core.DeepgramApiHttpResponse;
import com.deepgram.core.MediaTypes;
Expand Down Expand Up @@ -97,7 +96,7 @@ public DeepgramApiHttpResponse<GrantV1Response> grant(GrantV1Request request, Re
// unable to map error response, throwing generic error
}
Object errorBody = ObjectMappers.parseErrorBody(responseBodyString);
throw new DeepgramApiApiException(
throw new DeepgramApiException(
"Error with status code " + response.code(), response.code(), errorBody, response);
} catch (IOException e) {
throw new DeepgramApiException("Network error executing HTTP request", e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
package com.deepgram.resources.listen.v1.media;

import com.deepgram.core.ClientOptions;
import com.deepgram.core.DeepgramApiApiException;
import com.deepgram.core.DeepgramApiException;
import com.deepgram.core.DeepgramApiHttpResponse;
import com.deepgram.core.InputStreamRequestBody;
Expand Down Expand Up @@ -243,7 +242,7 @@ public void onResponse(@NotNull Call call, @NotNull Response response) throws IO
// unable to map error response, throwing generic error
}
Object errorBody = ObjectMappers.parseErrorBody(responseBodyString);
future.completeExceptionally(new DeepgramApiApiException(
future.completeExceptionally(new DeepgramApiException(
"Error with status code " + response.code(), response.code(), errorBody, response));
return;
} catch (IOException e) {
Expand Down Expand Up @@ -475,7 +474,7 @@ public void onResponse(@NotNull Call call, @NotNull Response response) throws IO
// unable to map error response, throwing generic error
}
Object errorBody = ObjectMappers.parseErrorBody(responseBodyString);
future.completeExceptionally(new DeepgramApiApiException(
future.completeExceptionally(new DeepgramApiException(
"Error with status code " + response.code(), response.code(), errorBody, response));
return;
} catch (IOException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
package com.deepgram.resources.listen.v1.media;

import com.deepgram.core.ClientOptions;
import com.deepgram.core.DeepgramApiApiException;
import com.deepgram.core.DeepgramApiException;
import com.deepgram.core.DeepgramApiHttpResponse;
import com.deepgram.core.InputStreamRequestBody;
Expand Down Expand Up @@ -233,7 +232,7 @@ public DeepgramApiHttpResponse<MediaTranscribeResponse> transcribeUrl(
// unable to map error response, throwing generic error
}
Object errorBody = ObjectMappers.parseErrorBody(responseBodyString);
throw new DeepgramApiApiException(
throw new DeepgramApiException(
"Error with status code " + response.code(), response.code(), errorBody, response);
} catch (IOException e) {
throw new DeepgramApiException("Network error executing HTTP request", e);
Expand Down Expand Up @@ -449,7 +448,7 @@ public DeepgramApiHttpResponse<MediaTranscribeResponse> transcribeFile(
// unable to map error response, throwing generic error
}
Object errorBody = ObjectMappers.parseErrorBody(responseBodyString);
throw new DeepgramApiApiException(
throw new DeepgramApiException(
"Error with status code " + response.code(), response.code(), errorBody, response);
} catch (IOException e) {
throw new DeepgramApiException("Network error executing HTTP request", e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
package com.deepgram.resources.manage.v1.models;

import com.deepgram.core.ClientOptions;
import com.deepgram.core.DeepgramApiApiException;
import com.deepgram.core.DeepgramApiException;
import com.deepgram.core.DeepgramApiHttpResponse;
import com.deepgram.core.ObjectMappers;
Expand Down Expand Up @@ -104,7 +103,7 @@ public void onResponse(@NotNull Call call, @NotNull Response response) throws IO
// unable to map error response, throwing generic error
}
Object errorBody = ObjectMappers.parseErrorBody(responseBodyString);
future.completeExceptionally(new DeepgramApiApiException(
future.completeExceptionally(new DeepgramApiException(
"Error with status code " + response.code(), response.code(), errorBody, response));
return;
} catch (IOException e) {
Expand Down Expand Up @@ -173,7 +172,7 @@ public void onResponse(@NotNull Call call, @NotNull Response response) throws IO
// unable to map error response, throwing generic error
}
Object errorBody = ObjectMappers.parseErrorBody(responseBodyString);
future.completeExceptionally(new DeepgramApiApiException(
future.completeExceptionally(new DeepgramApiException(
"Error with status code " + response.code(), response.code(), errorBody, response));
return;
} catch (IOException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
package com.deepgram.resources.manage.v1.models;

import com.deepgram.core.ClientOptions;
import com.deepgram.core.DeepgramApiApiException;
import com.deepgram.core.DeepgramApiException;
import com.deepgram.core.DeepgramApiHttpResponse;
import com.deepgram.core.ObjectMappers;
Expand Down Expand Up @@ -94,7 +93,7 @@ public DeepgramApiHttpResponse<ListModelsV1Response> list(
// unable to map error response, throwing generic error
}
Object errorBody = ObjectMappers.parseErrorBody(responseBodyString);
throw new DeepgramApiApiException(
throw new DeepgramApiException(
"Error with status code " + response.code(), response.code(), errorBody, response);
} catch (IOException e) {
throw new DeepgramApiException("Network error executing HTTP request", e);
Expand Down Expand Up @@ -147,7 +146,7 @@ public DeepgramApiHttpResponse<GetModelV1Response> get(String modelId, RequestOp
// unable to map error response, throwing generic error
}
Object errorBody = ObjectMappers.parseErrorBody(responseBodyString);
throw new DeepgramApiApiException(
throw new DeepgramApiException(
"Error with status code " + response.code(), response.code(), errorBody, response);
} catch (IOException e) {
throw new DeepgramApiException("Network error executing HTTP request", e);
Expand Down
Loading
Loading