Skip to content

Commit 1249539

Browse files
committed
fix: Removed last of the stringified response bodies in response messages
1 parent 9e0fd4f commit 1249539

File tree

13 files changed

+34
-22
lines changed

13 files changed

+34
-22
lines changed

src/app-check/app-check-api-client-internal.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ export class AppCheckApiClient {
185185
if (error.status && error.status in APP_CHECK_ERROR_CODE_MAPPING) {
186186
code = APP_CHECK_ERROR_CODE_MAPPING[error.status];
187187
}
188-
const message = error.message || `Unknown server error: ${response.text}`;
188+
const message = error.message || 'Unknown server error';
189189
return new FirebaseAppCheckError({ code, message, httpResponse: toHttpResponse(response), cause: err });
190190
}
191191

src/app-check/token-generator.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import {
2525
} from './app-check-api-client-internal';
2626
import { AppCheckTokenOptions } from './app-check-api';
2727
import { RequestResponseError } from '../utils/api-request';
28+
import { toHttpResponse } from '../utils/error';
2829

2930
const ONE_MINUTE_IN_SECONDS = 60;
3031
const ONE_MINUTE_IN_MILLIS = ONE_MINUTE_IN_SECONDS * 1000;
@@ -157,7 +158,7 @@ export function appCheckErrorFromCryptoSignerError(err: Error): Error {
157158
const errorResponse = httpError.response.data;
158159
if (errorResponse?.error) {
159160
const status = errorResponse.error.status;
160-
const description = errorResponse.error.message || JSON.stringify(httpError.response);
161+
const description = errorResponse.error.message || 'Unknown server error';
161162

162163
let code: AppCheckErrorCode = 'unknown-error';
163164
if (status && status in APP_CHECK_ERROR_CODE_MAPPING) {
@@ -166,12 +167,14 @@ export function appCheckErrorFromCryptoSignerError(err: Error): Error {
166167
return new FirebaseAppCheckError({
167168
code,
168169
message: `Error returned from server while signing a custom token: ${description}`,
170+
httpResponse: toHttpResponse(httpError.response),
169171
cause: err
170172
});
171173
}
172174
return new FirebaseAppCheckError({
173175
code: 'internal-error',
174-
message: 'Error returned from server: ' + JSON.stringify(errorResponse) + '.',
176+
message: 'Error returned from server.',
177+
httpResponse: toHttpResponse(httpError.response),
175178
cause: err
176179
});
177180
}

src/data-connect/data-connect-api-client-internal.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -413,7 +413,7 @@ export class DataConnectApiClient {
413413
if (error.status && error.status in DATA_CONNECT_ERROR_CODE_MAPPING) {
414414
code = DATA_CONNECT_ERROR_CODE_MAPPING[error.status];
415415
}
416-
const message = error.message || `Unknown server error: ${response.text}`;
416+
const message = error.message || 'Unknown server error';
417417
return new FirebaseDataConnectError({
418418
code,
419419
message,

src/extensions/extensions-api-client-internal.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ export class ExtensionsApiClient {
9292
});
9393
}
9494
const error = response.data?.error;
95-
const message = error?.message || `Unknown server error: ${response.text}`;
95+
const message = error?.message || 'Unknown server error';
9696
switch (error.code) {
9797
case 403:
9898
return new FirebaseExtensionsError({

src/firestore/firestore-internal.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -165,8 +165,8 @@ function initFirestore(app: App, databaseId: string, firestoreSettings?: Firesto
165165
throw new FirebaseFirestoreError({
166166
code: 'missing-dependencies',
167167
message: 'Failed to import the Cloud Firestore client library for Node.js. '
168-
+ 'Make sure to install the "@google-cloud/firestore" npm package. '
169-
+ `Original error: ${err}`,
168+
+ 'Make sure to install the "@google-cloud/firestore" npm package.',
169+
cause: err as Error,
170170
});
171171
}
172172

src/functions/functions-api-client-internal.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -397,7 +397,7 @@ export class FunctionsApiClient {
397397
if (error.status && error.status in FUNCTIONS_ERROR_CODE_MAPPING) {
398398
code = FUNCTIONS_ERROR_CODE_MAPPING[error.status];
399399
}
400-
const message = error.message || `Unknown server error: ${response.text}`;
400+
const message = error.message || 'Unknown server error';
401401
return new FirebaseFunctionsError({ code, message, httpResponse: toHttpResponse(response), cause: err });
402402
}
403403
}

src/installations/installations-request-handler.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
import { App } from '../app/index';
1919
import { FirebaseApp } from '../app/firebase-app';
20-
import { FirebaseInstallationsError, InstallationsClientErrorCode } from '../utils/error';
20+
import { FirebaseInstallationsError, InstallationsClientErrorCode, toHttpResponse } from '../utils/error';
2121
import {
2222
ApiSettings, AuthorizedHttpClient, HttpRequestConfig, RequestResponseError,
2323
} from '../utils/api-request';
@@ -33,7 +33,7 @@ const FIREBASE_IID_PATH = '/v1/';
3333
const FIREBASE_IID_TIMEOUT = 10000;
3434

3535
/** HTTP error codes raised by the backend server. */
36-
const ERROR_CODES: {[key: number]: string} = {
36+
const ERROR_CODES: { [key: number]: string; } = {
3737
400: 'Malformed installation ID argument.',
3838
401: 'Request not authorized.',
3939
403: 'Project does not match installation ID or the client does not have sufficient privileges.',
@@ -100,7 +100,12 @@ export class FirebaseInstallationsRequestHandler {
100100
const template: string = ERROR_CODES[response.status];
101101
const message: string = template ?
102102
`Installation ID "${apiSettings.getEndpoint()}": ${template}` : errorMessage;
103-
throw new FirebaseInstallationsError(InstallationsClientErrorCode.API_ERROR, message);
103+
throw new FirebaseInstallationsError({
104+
...InstallationsClientErrorCode.API_ERROR,
105+
message,
106+
httpResponse: toHttpResponse(response),
107+
cause: err,
108+
});
104109
}
105110
// In case of timeouts and other network errors, the HttpClient returns a
106111
// FirebaseError wrapped in the response. Simply throw it here.

src/machine-learning/machine-learning-api-client.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -401,7 +401,7 @@ export class MachineLearningApiClient {
401401
if (error.status && error.status in ERROR_CODE_MAPPING) {
402402
code = ERROR_CODE_MAPPING[error.status];
403403
}
404-
const message = error.message || `Unknown server error: ${response.text}`;
404+
const message = error.message || 'Unknown server error';
405405
return new FirebaseMachineLearningError({
406406
code,
407407
message,

src/project-management/project-management-api-request-internal.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import { FirebaseApp } from '../app/firebase-app';
1919
import {
2020
AuthorizedHttpClient, RequestResponseError, HttpMethod, HttpRequestConfig, ExponentialBackoffPoller,
2121
} from '../utils/api-request';
22-
import { FirebaseProjectManagementError, ProjectManagementErrorCode } from '../utils/error';
22+
import { FirebaseProjectManagementError, ProjectManagementErrorCode, HttpResponse, toHttpResponse } from '../utils/error';
2323
import { getSdkVersion } from '../utils/index';
2424
import * as validator from '../utils/validator';
2525
import { ShaCertificate } from './android-app';
@@ -68,7 +68,7 @@ export class ProjectManagementRequestHandler {
6868
`https://${PROJECT_MANAGEMENT_HOST_AND_PORT}${PROJECT_MANAGEMENT_BETA_PATH}`;
6969
private readonly httpClient: AuthorizedHttpClient;
7070

71-
private static wrapAndRethrowHttpError(errStatusCode: number, errText?: string): void {
71+
private static wrapAndRethrowHttpError(errStatusCode: number, errText?: string, httpResponse?: HttpResponse): void {
7272
let errorCode: ProjectManagementErrorCode;
7373
let errorMessage: string;
7474

@@ -111,7 +111,12 @@ export class ProjectManagementRequestHandler {
111111
}
112112
throw new FirebaseProjectManagementError({
113113
code: errorCode,
114-
message: `${errorMessage} Status code: ${errStatusCode}. Raw server response: "${errText}".`
114+
message: errorMessage,
115+
httpResponse: httpResponse || {
116+
status: errStatusCode,
117+
headers: {},
118+
data: errText,
119+
},
115120
});
116121
}
117122

@@ -332,7 +337,7 @@ export class ProjectManagementRequestHandler {
332337
.catch((err) => {
333338
if (err instanceof RequestResponseError) {
334339
ProjectManagementRequestHandler.wrapAndRethrowHttpError(
335-
err.response.status, err.response.text);
340+
err.response.status, err.response.text, toHttpResponse(err.response));
336341
}
337342
throw err;
338343
});

src/remote-config/remote-config-api-client-internal.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,7 @@ export class RemoteConfigApiClient {
270270
if (error.status && error.status in ERROR_CODE_MAPPING) {
271271
code = ERROR_CODE_MAPPING[error.status];
272272
}
273-
const message = error.message || `Unknown server error: ${response.text}`;
273+
const message = error.message || 'Unknown server error';
274274
return new FirebaseRemoteConfigError({ code, message, httpResponse: toHttpResponse(response), cause: err });
275275
}
276276

0 commit comments

Comments
 (0)