|
| 1 | +import { FirebaseError } from '@firebase/util'; |
1 | 2 | /**
|
2 | 3 | * @license
|
3 | 4 | * Copyright 2017 Google LLC
|
|
16 | 17 | */
|
17 | 18 | import { CONFIG_STORAGE_BUCKET_KEY } from './constants';
|
18 | 19 |
|
19 |
| -export class FirebaseStorageError implements Error { |
20 |
| - private code_: string; |
21 |
| - private message_: string; |
22 |
| - private serverResponse_: string | null; |
23 |
| - private name_: string; |
| 20 | +export class FirebaseStorageError extends FirebaseError { |
| 21 | + customData: { serverResponse: string | null }; |
24 | 22 |
|
25 | 23 | constructor(code: Code, message: string) {
|
26 |
| - this.code_ = prependCode(code); |
27 |
| - this.message_ = 'Firebase Storage: ' + message; |
28 |
| - this.serverResponse_ = null; |
29 |
| - this.name_ = 'FirebaseError'; |
30 |
| - } |
31 |
| - |
32 |
| - codeProp(): string { |
33 |
| - return this.code; |
| 24 | + super(prependCode(code), 'Firebase Storage: ' + message); |
| 25 | + // Without this, `instanceof FirebaseStorageError`, in tests for example, |
| 26 | + // returns false. |
| 27 | + Object.setPrototypeOf(this, FirebaseStorageError.prototype); |
| 28 | + this.customData = { serverResponse: null }; |
34 | 29 | }
|
35 | 30 |
|
36 | 31 | codeEquals(code: Code): boolean {
|
37 |
| - return prependCode(code) === this.codeProp(); |
38 |
| - } |
39 |
| - |
40 |
| - serverResponseProp(): string | null { |
41 |
| - return this.serverResponse_; |
42 |
| - } |
43 |
| - |
44 |
| - setServerResponseProp(serverResponse: string | null): void { |
45 |
| - this.serverResponse_ = serverResponse; |
46 |
| - } |
47 |
| - |
48 |
| - get name(): string { |
49 |
| - return this.name_; |
50 |
| - } |
51 |
| - |
52 |
| - get code(): string { |
53 |
| - return this.code_; |
| 32 | + return prependCode(code) === this.code; |
54 | 33 | }
|
55 | 34 |
|
56 | 35 | get message(): string {
|
57 |
| - if (this.serverResponse_) { |
58 |
| - return this.message_ + '\n' + this.serverResponse_; |
| 36 | + if (this.customData.serverResponse) { |
| 37 | + return this.message + '\n' + this.customData.serverResponse; |
59 | 38 | } else {
|
60 |
| - return this.message_; |
| 39 | + return this.message; |
61 | 40 | }
|
62 | 41 | }
|
63 | 42 |
|
64 | 43 | get serverResponse(): null | string {
|
65 |
| - return this.serverResponse_; |
| 44 | + return this.customData.serverResponse; |
| 45 | + } |
| 46 | + |
| 47 | + set serverResponse(serverResponse: string | null) { |
| 48 | + this.customData.serverResponse = serverResponse; |
66 | 49 | }
|
67 | 50 | }
|
68 | 51 |
|
|
0 commit comments