Return a 404 for device not found instead of 5XX (#34988)

Haven't fully QA'd as I am not sure how to repro locally(when I test the
pubsub arrives before we ever run the reconciler) however this should
cause 4xx to be returned from the website instead of 5xx for android
unenrolled. We use the exact same code on a different endpoint

<!-- Add the related story/sub-task/bug number, like Resolves #123, or
remove if NA -->
**Related issue:** Resolves #34988 partially. This just helps reduce
alerts to help-p1 and implements the interface that the server is
expecting
This commit is contained in:
Jordan Montgomery 2025-10-30 09:17:12 -04:00 committed by GitHub
parent cac0d3b424
commit e5589bc030
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -23,7 +23,8 @@ module.exports = {
success: { description: 'The device of an Android enterprise was successfully retrieved.' },
missingAuthHeader: { description: 'This request was missing an authorization header.', responseType: 'unauthorized'},
unauthorized: { description: 'Invalid authentication token.', responseType: 'unauthorized'},
notFound: { description: 'No Android enterprise found for this Fleet server.', responseType: 'notFound'},
notFound: { description: 'No Android enterprise found for this Fleet server.', responseType: 'notFound' },
deviceNoLongerManaged: { description: 'The device is no longer managed by the Android enterprise.', responseType: 'notFound' },
},
@ -81,6 +82,10 @@ module.exports = {
});
return getDeviceResult.data;
}).intercept((err) => {
let errorString = err.toString();
if (errorString.includes('Device is no longer being managed')) {
return {'deviceNoLongerManaged': 'The device is no longer managed by the Android enterprise.'};
}
return new Error(`When attempting to get a device for an Android enterprise (${androidEnterpriseId}), an error occurred. Error: ${err}`);
});