fix: handle OasstError correctly in OasstApiClient

This commit is contained in:
Jack Michaud
2023-01-06 10:15:07 -05:00
parent 083e8a869b
commit a9a3fc4e4a
+4 -3
View File
@@ -1,6 +1,6 @@
import { JWT } from "next-auth/jwt";
class OasstError {
export class OasstError {
message: string;
errorCode: number;
httpStatusCode: number;
@@ -31,12 +31,13 @@ export default 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();