mirror of
https://github.com/wassname/Open-Assistant.git
synced 2026-08-17 11:13:32 +08:00
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:
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user