Files
iNaturalistReactNative/src/api/places.js
Johannes Klein 929652fe14 Add some context to 429 errors (#2861)
* Add context to announcements API calls handleError

* Add context to handleError for calls in comments

* Add context to handleError for calls in computerVision

* Add context to handleError for calls in flags

* Add context to handleError for calls in identifications

* Add context to handleError for calls in messages

* Add context to handleError for calls in observations

* Add context to handleError for calls in observationSounds

* Add context to handleError for calls in places

* Add context to handleError for calls in projects

* Add context to handleError for calls in qualityMetrics

* Add context to handleError for calls in relationships

* Add context to handleError for calls in taxa

* Add context to handleError for calls in translations

* Add context to handleError for calls in users

* Move creation of error context to the handleError function

Also spread any other context that was passed into this function in the new context.

* Move logger for 429 errors to the handleError function

There are two codepaths that an error of 429 can follow here. Errors thrown from reactQueryRetry have a .status field whereas errors thrown from inaturalistjs have a .response.status field (and not the other in both cases).
I don't want to update the handleError function for now but instead keep its codepaths the same, so I added logging for both paths.

* Remove nullish values (null or undefined) from context
2025-04-30 11:11:23 +02:00

23 lines
498 B
JavaScript

// @flow
import inatjs from "inaturalistjs";
import handleError from "./error";
const fetchPlace = async (
id: number | Array<number>,
params: Object = {},
opts: Object = {}
): Promise<?Object> => {
try {
const { results } = await inatjs.places.fetch( id, params, opts );
return results && results.length > 0
? results[0]
: null;
} catch ( e ) {
return handleError( e, { context: { functionName: "fetchPlace", id, opts } } );
}
};
export default fetchPlace;