Skip to content

Commit 82d6dc1

Browse files
authored
fix: Moved FirebaseError interface to app module (#1164)
1 parent a51d9c2 commit 82d6dc1

File tree

13 files changed

+110
-100
lines changed

13 files changed

+110
-100
lines changed

etc/firebase-admin.app.api.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,20 @@ export interface Credential {
3737
// @public (undocumented)
3838
export function deleteApp(app: App): Promise<void>;
3939

40+
// @public
41+
export interface FirebaseArrayIndexError {
42+
error: FirebaseError;
43+
index: number;
44+
}
45+
46+
// @public
47+
export interface FirebaseError {
48+
code: string;
49+
message: string;
50+
stack?: string;
51+
toJSON(): object;
52+
}
53+
4054
// @public (undocumented)
4155
export function getApp(name?: string): App;
4256

src/app/core.ts

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,3 +123,82 @@ export interface App {
123123
*/
124124
options: AppOptions;
125125
}
126+
127+
/**
128+
* `FirebaseError` is a subclass of the standard JavaScript `Error` object. In
129+
* addition to a message string and stack trace, it contains a string code.
130+
*/
131+
export interface FirebaseError {
132+
133+
/**
134+
* Error codes are strings using the following format: `"service/string-code"`.
135+
* Some examples include `"auth/invalid-uid"` and
136+
* `"messaging/invalid-recipient"`.
137+
*
138+
* While the message for a given error can change, the code will remain the same
139+
* between backward-compatible versions of the Firebase SDK.
140+
*/
141+
code: string;
142+
143+
/**
144+
* An explanatory message for the error that just occurred.
145+
*
146+
* This message is designed to be helpful to you, the developer. Because
147+
* it generally does not convey meaningful information to end users,
148+
* this message should not be displayed in your application.
149+
*/
150+
message: string;
151+
152+
/**
153+
* A string value containing the execution backtrace when the error originally
154+
* occurred.
155+
*
156+
* This information can be useful to you and can be sent to
157+
* {@link https://firebase.google.com/support/ Firebase Support} to help
158+
* explain the cause of an error.
159+
*/
160+
stack?: string;
161+
162+
/**
163+
* @return A JSON-serializable representation of this object.
164+
*/
165+
toJSON(): object;
166+
}
167+
168+
/**
169+
* Composite type which includes both a `FirebaseError` object and an index
170+
* which can be used to get the errored item.
171+
*
172+
* @example
173+
* ```javascript
174+
* var registrationTokens = [token1, token2, token3];
175+
* admin.messaging().subscribeToTopic(registrationTokens, 'topic-name')
176+
* .then(function(response) {
177+
* if (response.failureCount > 0) {
178+
* console.log("Following devices unsucessfully subscribed to topic:");
179+
* response.errors.forEach(function(error) {
180+
* var invalidToken = registrationTokens[error.index];
181+
* console.log(invalidToken, error.error);
182+
* });
183+
* } else {
184+
* console.log("All devices successfully subscribed to topic:", response);
185+
* }
186+
* })
187+
* .catch(function(error) {
188+
* console.log("Error subscribing to topic:", error);
189+
* });
190+
*```
191+
*/
192+
export interface FirebaseArrayIndexError {
193+
194+
/**
195+
* The index of the errored item within the original array passed as part of the
196+
* called API method.
197+
*/
198+
index: number;
199+
200+
/**
201+
* The error object.
202+
*/
203+
error: FirebaseError;
204+
}

src/app/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
import { getSdkVersion } from '../utils';
1919

20-
export { App, AppOptions } from './core'
20+
export { App, AppOptions, FirebaseArrayIndexError, FirebaseError } from './core'
2121
export { initializeApp, getApp, getApps, deleteApp } from './lifecycle';
2222

2323
export { Credential, ServiceAccount, GoogleOAuthAccessToken } from './credential';

src/auth/user-import-builder.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,11 @@
1414
* limitations under the License.
1515
*/
1616

17+
import { FirebaseArrayIndexError } from '../app/index';
1718
import { deepCopy, deepExtend } from '../utils/deep-copy';
1819
import * as utils from '../utils';
1920
import * as validator from '../utils/validator';
2021
import { AuthClientErrorCode, FirebaseAuthError } from '../utils/error';
21-
import { FirebaseArrayIndexError } from '../firebase-namespace-api';
2222
import {
2323
UpdateMultiFactorInfoRequest, UpdatePhoneMultiFactorInfoRequest, MultiFactorUpdateSettings
2424
} from './auth-config';

src/firebase-namespace-api.ts

Lines changed: 0 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -29,85 +29,6 @@ import { App as AppCore, AppOptions } from './app/index';
2929

3030
export * from './app/index';
3131

32-
/**
33-
* `FirebaseError` is a subclass of the standard JavaScript `Error` object. In
34-
* addition to a message string and stack trace, it contains a string code.
35-
*/
36-
export interface FirebaseError {
37-
38-
/**
39-
* Error codes are strings using the following format: `"service/string-code"`.
40-
* Some examples include `"auth/invalid-uid"` and
41-
* `"messaging/invalid-recipient"`.
42-
*
43-
* While the message for a given error can change, the code will remain the same
44-
* between backward-compatible versions of the Firebase SDK.
45-
*/
46-
code: string;
47-
48-
/**
49-
* An explanatory message for the error that just occurred.
50-
*
51-
* This message is designed to be helpful to you, the developer. Because
52-
* it generally does not convey meaningful information to end users,
53-
* this message should not be displayed in your application.
54-
*/
55-
message: string;
56-
57-
/**
58-
* A string value containing the execution backtrace when the error originally
59-
* occurred.
60-
*
61-
* This information can be useful to you and can be sent to
62-
* {@link https://firebase.google.com/support/ Firebase Support} to help
63-
* explain the cause of an error.
64-
*/
65-
stack?: string;
66-
67-
/**
68-
* @return A JSON-serializable representation of this object.
69-
*/
70-
toJSON(): object;
71-
}
72-
73-
/**
74-
* Composite type which includes both a `FirebaseError` object and an index
75-
* which can be used to get the errored item.
76-
*
77-
* @example
78-
* ```javascript
79-
* var registrationTokens = [token1, token2, token3];
80-
* admin.messaging().subscribeToTopic(registrationTokens, 'topic-name')
81-
* .then(function(response) {
82-
* if (response.failureCount > 0) {
83-
* console.log("Following devices unsucessfully subscribed to topic:");
84-
* response.errors.forEach(function(error) {
85-
* var invalidToken = registrationTokens[error.index];
86-
* console.log(invalidToken, error.error);
87-
* });
88-
* } else {
89-
* console.log("All devices successfully subscribed to topic:", response);
90-
* }
91-
* })
92-
* .catch(function(error) {
93-
* console.log("Error subscribing to topic:", error);
94-
* });
95-
*```
96-
*/
97-
export interface FirebaseArrayIndexError {
98-
99-
/**
100-
* The index of the errored item within the original array passed as part of the
101-
* called API method.
102-
*/
103-
index: number;
104-
105-
/**
106-
* The error object.
107-
*/
108-
error: FirebaseError;
109-
}
110-
11132
// eslint-disable-next-line @typescript-eslint/no-namespace
11233
export namespace app {
11334
/**

src/messaging/messaging-api.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
* limitations under the License.
1616
*/
1717

18-
import { FirebaseArrayIndexError, FirebaseError } from '../firebase-namespace-api';
18+
import { FirebaseArrayIndexError, FirebaseError } from '../app/index';
1919

2020
export interface BaseMessage {
2121
data?: { [key: string]: string };

test/unit/auth/auth.spec.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,6 @@ import * as chaiAsPromised from 'chai-as-promised';
2727
import * as utils from '../utils';
2828
import * as mocks from '../../resources/mocks';
2929

30-
import { Auth, TenantAwareAuth, BaseAuth } from '../../../src/auth/index';
31-
import { UserRecord } from '../../../src/auth/user-record';
3230
import { FirebaseApp } from '../../../src/app/firebase-app';
3331
import {
3432
AuthRequestHandler, TenantAwareAuthRequestHandler, AbstractAuthRequestHandler,
@@ -41,10 +39,12 @@ import {
4139
OIDCConfig, SAMLConfig, OIDCConfigServerResponse, SAMLConfigServerResponse,
4240
} from '../../../src/auth/auth-config';
4341
import { deepCopy } from '../../../src/utils/deep-copy';
44-
import { TenantManager } from '../../../src/auth/tenant-manager';
4542
import { ServiceAccountCredential } from '../../../src/app/credential-internal';
4643
import { HttpClient } from '../../../src/utils/api-request';
47-
import { DecodedIdToken, UpdateRequest, AuthProviderConfigFilter } from '../../../src/auth/index';
44+
import {
45+
Auth, TenantAwareAuth, BaseAuth, UserRecord, DecodedIdToken,
46+
UpdateRequest, AuthProviderConfigFilter, TenantManager,
47+
} from '../../../src/auth/index';
4848

4949
chai.should();
5050
chai.use(sinonChai);

test/unit/auth/tenant-manager.spec.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,10 @@ import * as chaiAsPromised from 'chai-as-promised';
2525
import * as mocks from '../../resources/mocks';
2626
import { FirebaseApp } from '../../../src/app/firebase-app';
2727
import { AuthRequestHandler } from '../../../src/auth/auth-api-request';
28-
import { Tenant, TenantServerResponse } from '../../../src/auth/tenant';
29-
import { TenantManager } from '../../../src/auth/tenant-manager';
28+
import { TenantServerResponse } from '../../../src/auth/tenant';
3029
import { AuthClientErrorCode, FirebaseAuthError } from '../../../src/utils/error';
3130
import {
32-
CreateTenantRequest, UpdateTenantRequest, ListTenantsResult,
31+
CreateTenantRequest, UpdateTenantRequest, ListTenantsResult, Tenant, TenantManager,
3332
} from '../../../src/auth/index';
3433

3534
chai.should();

test/unit/auth/tenant.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@ import * as chaiAsPromised from 'chai-as-promised';
2121

2222
import { deepCopy } from '../../../src/utils/deep-copy';
2323
import { EmailSignInConfig, MultiFactorAuthConfig } from '../../../src/auth/auth-config';
24-
import { Tenant, TenantServerResponse } from '../../../src/auth/tenant';
24+
import { TenantServerResponse } from '../../../src/auth/tenant';
2525
import {
26-
CreateTenantRequest, UpdateTenantRequest, EmailSignInProviderConfig,
26+
CreateTenantRequest, UpdateTenantRequest, EmailSignInProviderConfig, Tenant,
2727
} from '../../../src/auth/index';
2828

2929
chai.should();

test/unit/instance-id/instance-id.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ import * as chaiAsPromised from 'chai-as-promised';
2626
import * as utils from '../utils';
2727
import * as mocks from '../../resources/mocks';
2828

29-
import { InstanceId } from '../../../src/instance-id/instance-id';
29+
import { InstanceId } from '../../../src/instance-id/index';
3030
import { FirebaseInstanceIdRequestHandler } from '../../../src/instance-id/instance-id-request-internal';
3131
import { FirebaseApp } from '../../../src/app/firebase-app';
3232
import { FirebaseInstanceIdError, InstanceIdClientErrorCode } from '../../../src/utils/error';

0 commit comments

Comments
 (0)