@etherspot/prime-sdk
Version:
Etherspot Prime (Account Abstraction) SDK
33 lines (32 loc) • 1.17 kB
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
exports.catchApiError = void 0;
const common_1 = require("../../common");
const exceptions_1 = require("../exceptions");
function catchApiError(error) {
let exception;
try {
const { code, errors } = error.graphQLErrors[0].extensions;
switch (code) {
case exceptions_1.HttpExceptionCodes.BadRequest:
case exceptions_1.HttpExceptionCodes.Unauthorized:
case exceptions_1.HttpExceptionCodes.Forbidden:
case exceptions_1.HttpExceptionCodes.NotFound:
exception = new exceptions_1.HttpException(code);
break;
case exceptions_1.HttpExceptionCodes.InternalServerError:
exception = new exceptions_1.HttpException(code, error.message);
break;
case exceptions_1.HttpExceptionCodes.ValidationError:
exception = new common_1.ValidationException(errors);
break;
}
}
catch (err) {
}
if (!exception) {
exception = error;
}
throw exception;
}
exports.catchApiError = catchApiError;
;