UNPKG

realm-object-server

Version:

Realm Object Server

209 lines 7 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const JSONError_1 = require("./JSONError"); class RealmProblem extends JSONError_1.JSONError { get type() { return this._type || `https://docs.realm.io/server/troubleshoot/errors#${this.path}`; } set type(newType) { this._type = newType; } toJSON() { const json = super.toJSON(); json.code = this.code; return json; } constructor(params, defaultTitle) { super(Object.assign({ title: params.title || defaultTitle }, params)); } } exports.RealmProblem = RealmProblem; class GenericRealmProblem extends RealmProblem { constructor(code, params) { super(params, undefined); this.code = code; } } exports.GenericRealmProblem = GenericRealmProblem; class InvalidParameters extends RealmProblem { constructor(...parameters) { super({}, "Your request parameters did not validate."); this.path = "invalid-parameters"; this.code = 601; this.invalidParams = (parameters || []).map((parameter) => { if (typeof parameter === "string") { return { name: parameter, reason: `Invalid parameter '${parameter}'!` }; } return parameter; }); } get message() { return super.message + (this.invalidParams || []).map((param) => { return ` '${param.name}': ${param.reason}`; }).join("; "); } toJSON() { const json = super.toJSON(); json.invalid_params = this.invalidParams; return json; } } exports.InvalidParameters = InvalidParameters; class MissingParameters extends InvalidParameters { constructor(...parameters) { super(...(parameters || []).map((parameter) => { return { name: parameter, reason: `Missing parameter '${parameter}'!`, }; })); this.path = "missing-parameters"; this.code = 602; this.title = "Your request did not validate because of missing parameters."; } } exports.MissingParameters = MissingParameters; class InvalidCredentials extends RealmProblem { constructor(params = {}) { super(params, "The provided credentials are invalid or the user does not exist."); this.path = "invalid-credentials"; this.status = 401; this.code = 611; } } exports.InvalidCredentials = InvalidCredentials; class UnknownAccount extends RealmProblem { constructor(params = {}) { super(params, "The account does not exist."); this.path = "unknown-account"; this.status = 404; this.code = 612; } } exports.UnknownAccount = UnknownAccount; class ExistingAccount extends RealmProblem { constructor(params = {}) { super(params, "The account cannot be registered as it exists already."); this.path = "existing-account"; this.status = 400; this.code = 613; } } exports.ExistingAccount = ExistingAccount; class AccessDenied extends RealmProblem { constructor(params = {}) { super(params, "The path is invalid or current user has no access."); this.path = "access-denied"; this.status = 403; this.code = 614; } } exports.AccessDenied = AccessDenied; class InvalidRealmType extends RealmProblem { constructor(expectedType, actualType) { super({}, "The type of the Realm file was invalid."); this.path = "invalid-realm-type"; this.status = 400; this.code = 619; this.expectedType = expectedType; this.actualType = actualType; } get message() { return `${super.message} Expected ${this.expectedType} but got ${this.actualType}.`; } } exports.InvalidRealmType = InvalidRealmType; class ExpiredRefreshToken extends RealmProblem { constructor(params = {}) { super(params, "The refresh token is expired."); this.path = "expired-refresh-token"; this.status = 401; this.code = 615; } } exports.ExpiredRefreshToken = ExpiredRefreshToken; class InvalidHost extends RealmProblem { constructor(params = {}) { super(params, "The server is not authoritative for this URL."); this.path = "invalid-host"; this.status = 400; this.code = 616; } } exports.InvalidHost = InvalidHost; class RealmNotFound extends RealmProblem { constructor(params = {}) { super(params, "The Realm could not be found"); this.path = "realm-not-found"; this.status = 404; this.code = 617; } } exports.RealmNotFound = RealmNotFound; class UnknownUser extends RealmProblem { constructor(params = {}) { super(params, "The user does not exist."); this.path = "unknown-user"; this.status = 404; this.code = 618; } } exports.UnknownUser = UnknownUser; class ExpiredPermissionOffer extends RealmProblem { constructor(params = {}) { super(params, "The permission offer is expired."); this.path = "expired-permission-offer"; this.status = 403; this.code = 701; } } exports.ExpiredPermissionOffer = ExpiredPermissionOffer; class AmbiguousPermissionOfferToken extends RealmProblem { constructor(params = {}) { super(params, "The token used in the PermissionOfferResponse does match more than a single PermissionOffer."); this.path = "ambiguous-permission-offer"; this.status = 403; this.code = 702; } } exports.AmbiguousPermissionOfferToken = AmbiguousPermissionOfferToken; class FileMayNotBeShared extends RealmProblem { constructor(params = {}) { super(params, "The Realm file at the specified path is not available for shared access."); this.path = "file-may-not-be-shared"; this.status = 403; this.code = 703; } } exports.FileMayNotBeShared = FileMayNotBeShared; class ServerMisconfiguration extends RealmProblem { constructor(params = {}) { super(params, "The server was configured in a way that is inconsistent with its internal state."); this.path = "server-misconfiguration"; this.status = 500; this.code = 801; } } exports.ServerMisconfiguration = ServerMisconfiguration; class ServiceUnavailable extends RealmProblem { constructor(params = {}) { super(params, "The requested service is temporarily unavailable."); this.path = "service-unavailable"; this.status = 503; this.code = 802; } } exports.ServiceUnavailable = ServiceUnavailable; class NotSupported extends RealmProblem { constructor(params = {}) { super(params, "The server was not configured to support the requested operation."); this.path = "not-enabled"; this.status = 501; this.code = 803; } } exports.NotSupported = NotSupported; //# sourceMappingURL=RealmProblem.js.map