summaryrefslogtreecommitdiff
path: root/packages/idb-bridge/src/util/errors.ts
blob: bbf9498c157346565155278a345de707d641b6df (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
/*
 Copyright 2017 Jeremy Scheff

 Licensed under the Apache License, Version 2.0 (the "License");
 you may not use this file except in compliance with the License.
 You may obtain a copy of the License at

 http://www.apache.org/licenses/LICENSE-2.0

 Unless required by applicable law or agreed to in writing, software
 distributed under the License is distributed on an "AS IS" BASIS,
 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
 or implied. See the License for the specific language governing
 permissions and limitations under the License.
 */


/* tslint:disable: max-classes-per-file max-line-length */

const messages = {
    AbortError:
        "A request was aborted, for example through a call to IDBTransaction.abort.",
    ConstraintError:
        "A mutation operation in the transaction failed because a constraint was not satisfied. For example, an object such as an object store or index already exists and a request attempted to create a new one.",
    DataCloneError:
        "The data being stored could not be cloned by the internal structured cloning algorithm.",
    DataError: "Data provided to an operation does not meet requirements.",
    InvalidAccessError:
        "An invalid operation was performed on an object. For example transaction creation attempt was made, but an empty scope was provided.",
    InvalidStateError:
        "An operation was called on an object on which it is not allowed or at a time when it is not allowed. Also occurs if a request is made on a source object that has been deleted or removed. Use TransactionInactiveError or ReadOnlyError when possible, as they are more specific variations of InvalidStateError.",
    NotFoundError:
        "The operation failed because the requested database object could not be found. For example, an object store did not exist but was being opened.",
    ReadOnlyError:
        'The mutating operation was attempted in a "readonly" transaction.',
    TransactionInactiveError:
        "A request was placed against a transaction which is currently not active, or which is finished.",
    VersionError:
        "An attempt was made to open a database using a lower version than the existing version.",
};

export class AbortError extends Error {
    constructor(message = messages.AbortError) {
        super();
        this.name = "AbortError";
        this.message = message;
    }
}

export class ConstraintError extends Error {
    constructor(message = messages.ConstraintError) {
        super();
        this.name = "ConstraintError";
        this.message = message;
    }
}

export class DataCloneError extends Error {
    constructor(message = messages.DataCloneError) {
        super();
        this.name = "DataCloneError";
        this.message = message;
    }
}

export class DataError extends Error {
    constructor(message = messages.DataError) {
        super();
        this.name = "DataError";
        this.message = message;
    }
}

export class InvalidAccessError extends Error {
    constructor(message = messages.InvalidAccessError) {
        super();
        this.name = "InvalidAccessError";
        this.message = message;
    }
}

export class InvalidStateError extends Error {
    constructor(message = messages.InvalidStateError) {
        super();
        this.name = "InvalidStateError";
        this.message = message;
    }
}

export class NotFoundError extends Error {
    constructor(message = messages.NotFoundError) {
        super();
        this.name = "NotFoundError";
        this.message = message;
    }
}

export class ReadOnlyError extends Error {
    constructor(message = messages.ReadOnlyError) {
        super();
        this.name = "ReadOnlyError";
        this.message = message;
    }
}

export class TransactionInactiveError extends Error {
    constructor(message = messages.TransactionInactiveError) {
        super();
        this.name = "TransactionInactiveError";
        this.message = message;
    }
}

export class VersionError extends Error {
    constructor(message = messages.VersionError) {
        super();
        this.name = "VersionError";
        this.message = message;
    }
}