diff --git a/03_lesson/src/features/posts/postsSlice.js b/03_lesson/src/features/posts/postsSlice.js index 50449eb..d1e2649 100644 --- a/03_lesson/src/features/posts/postsSlice.js +++ b/03_lesson/src/features/posts/postsSlice.js @@ -11,21 +11,13 @@ const initialState = { } export const fetchPosts = createAsyncThunk('posts/fetchPosts', async () => { - try { - const response = await axios.get(POSTS_URL) - return [...response.data]; - } catch (err) { - return err.message; - } + const response = await axios.get(POSTS_URL) + return response.data }) export const addNewPost = createAsyncThunk('posts/addNewPost', async (initialPost) => { - try { - const response = await axios.post(POSTS_URL, initialPost) - return response.data - } catch (err) { - return err.message; - } + const response = await axios.post(POSTS_URL, initialPost) + return response.data }) const postsSlice = createSlice({ diff --git a/03_lesson/src/features/users/usersSlice.js b/03_lesson/src/features/users/usersSlice.js index 63050e5..188f5a5 100644 --- a/03_lesson/src/features/users/usersSlice.js +++ b/03_lesson/src/features/users/usersSlice.js @@ -6,12 +6,8 @@ const USERS_URL = 'https://jsonplaceholder.typicode.com/users'; const initialState = [] export const fetchUsers = createAsyncThunk('users/fetchUsers', async () => { - try { - const response = await axios.get(USERS_URL); - return [...response.data]; - } catch (err) { - return err.message; - } + const response = await axios.get(USERS_URL); + return response.data }) const usersSlice = createSlice({ diff --git a/04_lesson/src/features/posts/postsSlice.js b/04_lesson/src/features/posts/postsSlice.js index fa5da45..354f55c 100644 --- a/04_lesson/src/features/posts/postsSlice.js +++ b/04_lesson/src/features/posts/postsSlice.js @@ -11,21 +11,13 @@ const initialState = { } export const fetchPosts = createAsyncThunk('posts/fetchPosts', async () => { - try { - const response = await axios.get(POSTS_URL) - return [...response.data]; - } catch (err) { - return err.message; - } + const response = await axios.get(POSTS_URL) + return response.data }) export const addNewPost = createAsyncThunk('posts/addNewPost', async (initialPost) => { - try { - const response = await axios.post(POSTS_URL, initialPost) - return response.data - } catch (err) { - return err.message; - } + const response = await axios.post(POSTS_URL, initialPost) + return response.data }) export const updatePost = createAsyncThunk('posts/updatePost', async (initialPost) => { diff --git a/04_lesson/src/features/users/usersSlice.js b/04_lesson/src/features/users/usersSlice.js index 63050e5..188f5a5 100644 --- a/04_lesson/src/features/users/usersSlice.js +++ b/04_lesson/src/features/users/usersSlice.js @@ -6,12 +6,8 @@ const USERS_URL = 'https://jsonplaceholder.typicode.com/users'; const initialState = [] export const fetchUsers = createAsyncThunk('users/fetchUsers', async () => { - try { - const response = await axios.get(USERS_URL); - return [...response.data]; - } catch (err) { - return err.message; - } + const response = await axios.get(USERS_URL); + return response.data }) const usersSlice = createSlice({ diff --git a/04_lesson_starter/src/features/posts/postsSlice.js b/04_lesson_starter/src/features/posts/postsSlice.js index 50449eb..d1e2649 100644 --- a/04_lesson_starter/src/features/posts/postsSlice.js +++ b/04_lesson_starter/src/features/posts/postsSlice.js @@ -11,21 +11,13 @@ const initialState = { } export const fetchPosts = createAsyncThunk('posts/fetchPosts', async () => { - try { - const response = await axios.get(POSTS_URL) - return [...response.data]; - } catch (err) { - return err.message; - } + const response = await axios.get(POSTS_URL) + return response.data }) export const addNewPost = createAsyncThunk('posts/addNewPost', async (initialPost) => { - try { - const response = await axios.post(POSTS_URL, initialPost) - return response.data - } catch (err) { - return err.message; - } + const response = await axios.post(POSTS_URL, initialPost) + return response.data }) const postsSlice = createSlice({ diff --git a/04_lesson_starter/src/features/users/usersSlice.js b/04_lesson_starter/src/features/users/usersSlice.js index 63050e5..188f5a5 100644 --- a/04_lesson_starter/src/features/users/usersSlice.js +++ b/04_lesson_starter/src/features/users/usersSlice.js @@ -6,12 +6,8 @@ const USERS_URL = 'https://jsonplaceholder.typicode.com/users'; const initialState = [] export const fetchUsers = createAsyncThunk('users/fetchUsers', async () => { - try { - const response = await axios.get(USERS_URL); - return [...response.data]; - } catch (err) { - return err.message; - } + const response = await axios.get(USERS_URL); + return response.data }) const usersSlice = createSlice({