Skip to content

Commit

Permalink
feat: mask sensitive data in api error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelfreund committed Jan 14, 2025
1 parent f59bbaa commit 9c95973
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/core/service/api/api.service.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { ApiError } from '../../../shared/error/api.error.js';
import { maskSensitiveData } from '../../../shared/lib/util/object.util.js';

export class ApiService {
#baseUrl: string;
Expand Down Expand Up @@ -42,15 +43,16 @@ export class ApiService {
});

if (!response.ok) {
const errorDetails = await response.json().catch(() => null);
const errorMessage = errorDetails?.message || response.statusText || 'An unknown error occurred';
const errorBody = maskSensitiveData(body as unknown as Record<string, unknown>);
const errorResponse = await response.json().catch(() => null);
const errorMessage = errorResponse?.message || response.statusText || 'An unknown error occurred';
const statusCode = response.status;

throw new ApiError(errorMessage, statusCode, {
endpoint,
method,
body,
response: errorDetails,
body: errorBody,
response: errorResponse,
});
}

Expand Down

0 comments on commit 9c95973

Please sign in to comment.