Merge pull request #447 from LAION-AI/jm/tests-for-javascript-oasst-api-client

tests + fix: #354 Add tests for OasstApiClient and fix handling of OasstError
This commit is contained in:
Keith Stevens
2023-01-07 07:57:06 +09:00
committed by GitHub
2 changed files with 69 additions and 7 deletions
+4 -3
View File
@@ -5,7 +5,7 @@ declare global {
var oasstApiClient: OasstApiClient | undefined;
}
class OasstError {
export class OasstError {
message: string;
errorCode: number;
httpStatusCode: number;
@@ -36,12 +36,13 @@ export class OasstApiClient {
if (resp.status >= 300) {
const errorText = await resp.text();
let error: any;
try {
const error = JSON.parse(errorText);
throw new OasstError(error.message, error.error_code, resp.status);
error = JSON.parse(errorText);
} catch (e) {
throw new OasstError(errorText, 0, resp.status);
}
throw new OasstError(error.message, error.error_code, resp.status);
}
return await resp.json();