Skip to content

Commit 91abce8

Browse files
authored
Merge pull request #1198 from data-for-change/1195-ref-modify-patch
add async functionality, print error
2 parents 31a15ab + aefa1d0 commit 91abce8

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

src/services/news.data.service.ts

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -68,12 +68,12 @@ function onErrorFetchNewsFlash() {
6868
return errorArr;
6969
}
7070

71-
export function updateNews(
71+
export const updateNews = async (
7272
newsId: number,
7373
newLocationQualification: any,
7474
streetLocation: IStreetData | null,
7575
gpsLocation: IGpsData | null
76-
) {
76+
): Promise<any> => {
7777
const payload: any = {
7878
newsflash_location_qualification: newLocationQualification,
7979
};
@@ -87,8 +87,12 @@ export function updateNews(
8787
}
8888

8989
const url = `${NEWS_FLASH_API}/${newsId}`;
90-
return axios
91-
.patch(url, payload, { withCredentials: true })
92-
.then((res) => res.data)
93-
.catch(onErrorFetchNewsFlash);
94-
}
90+
91+
try {
92+
const response = await axios.patch(url, payload, { withCredentials: true });
93+
return response.data;
94+
} catch (error) {
95+
console.error('Error updating newsflash:', error);
96+
return onErrorFetchNewsFlash();
97+
}
98+
};

0 commit comments

Comments
 (0)