Skip to content

Commit d156595

Browse files
committed
fix(LLMO-4070): handle Configuration.findLatest errors in patchAuditForSite
findLatest throws (not returns null) when S3 throws NoSuchBucket or AccessDenied. Wrap in try-catch so unavailable configuration skips the audit-type check instead of surfacing a 500.
1 parent 214a298 commit d156595

2 files changed

Lines changed: 23 additions & 1 deletion

File tree

src/controllers/audits.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,12 @@ function AuditsController(ctx) {
218218
return forbidden('User does not have access to this site');
219219
}
220220

221-
const configuration = await Configuration.findLatest();
221+
let configuration;
222+
try {
223+
configuration = await Configuration.findLatest();
224+
} catch {
225+
// Configuration unavailable — skip audit-type registration check
226+
}
222227
if (configuration) {
223228
const registeredAudits = configuration.getHandlers();
224229
if (!registeredAudits[auditType]) {

test/controllers/audits.test.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -856,6 +856,23 @@ describe('Audits Controller', () => {
856856
);
857857
});
858858

859+
it('proceeds without audit-type check when Configuration.findLatest throws', async () => {
860+
mockDataAccess.Configuration.findLatest.rejects(new Error('S3 bucket not found'));
861+
const auditType = 'broken-backlinks';
862+
863+
const context = {
864+
params: { siteId, auditType },
865+
data: {},
866+
};
867+
868+
const result = await auditsController.patchAuditForSite(context);
869+
870+
// S3 unavailability must not surface as 500 — controller continues and hits normal validation
871+
expect(result.status).to.equal(400);
872+
const error = await result.json();
873+
expect(error).to.have.property('message', 'No updates provided');
874+
});
875+
859876
it('merges manual overwrites correctly', async () => {
860877
const auditType = 'broken-backlinks';
861878
const manualOverwrites = [

0 commit comments

Comments
 (0)