Removed try/catch from async thunks. Letting promise.rejected cases do their work.
This commit is contained in:
parent
82d81f76a8
commit
47554d03da
@ -11,21 +11,13 @@ const initialState = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export const fetchPosts = createAsyncThunk('posts/fetchPosts', async () => {
|
export const fetchPosts = createAsyncThunk('posts/fetchPosts', async () => {
|
||||||
try {
|
const response = await axios.get(POSTS_URL)
|
||||||
const response = await axios.get(POSTS_URL)
|
return response.data
|
||||||
return [...response.data];
|
|
||||||
} catch (err) {
|
|
||||||
return err.message;
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
|
|
||||||
export const addNewPost = createAsyncThunk('posts/addNewPost', async (initialPost) => {
|
export const addNewPost = createAsyncThunk('posts/addNewPost', async (initialPost) => {
|
||||||
try {
|
const response = await axios.post(POSTS_URL, initialPost)
|
||||||
const response = await axios.post(POSTS_URL, initialPost)
|
return response.data
|
||||||
return response.data
|
|
||||||
} catch (err) {
|
|
||||||
return err.message;
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
|
|
||||||
const postsSlice = createSlice({
|
const postsSlice = createSlice({
|
||||||
|
@ -6,12 +6,8 @@ const USERS_URL = 'https://jsonplaceholder.typicode.com/users';
|
|||||||
const initialState = []
|
const initialState = []
|
||||||
|
|
||||||
export const fetchUsers = createAsyncThunk('users/fetchUsers', async () => {
|
export const fetchUsers = createAsyncThunk('users/fetchUsers', async () => {
|
||||||
try {
|
const response = await axios.get(USERS_URL);
|
||||||
const response = await axios.get(USERS_URL);
|
return response.data
|
||||||
return [...response.data];
|
|
||||||
} catch (err) {
|
|
||||||
return err.message;
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
|
|
||||||
const usersSlice = createSlice({
|
const usersSlice = createSlice({
|
||||||
|
@ -11,21 +11,13 @@ const initialState = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export const fetchPosts = createAsyncThunk('posts/fetchPosts', async () => {
|
export const fetchPosts = createAsyncThunk('posts/fetchPosts', async () => {
|
||||||
try {
|
const response = await axios.get(POSTS_URL)
|
||||||
const response = await axios.get(POSTS_URL)
|
return response.data
|
||||||
return [...response.data];
|
|
||||||
} catch (err) {
|
|
||||||
return err.message;
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
|
|
||||||
export const addNewPost = createAsyncThunk('posts/addNewPost', async (initialPost) => {
|
export const addNewPost = createAsyncThunk('posts/addNewPost', async (initialPost) => {
|
||||||
try {
|
const response = await axios.post(POSTS_URL, initialPost)
|
||||||
const response = await axios.post(POSTS_URL, initialPost)
|
return response.data
|
||||||
return response.data
|
|
||||||
} catch (err) {
|
|
||||||
return err.message;
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
|
|
||||||
export const updatePost = createAsyncThunk('posts/updatePost', async (initialPost) => {
|
export const updatePost = createAsyncThunk('posts/updatePost', async (initialPost) => {
|
||||||
|
@ -6,12 +6,8 @@ const USERS_URL = 'https://jsonplaceholder.typicode.com/users';
|
|||||||
const initialState = []
|
const initialState = []
|
||||||
|
|
||||||
export const fetchUsers = createAsyncThunk('users/fetchUsers', async () => {
|
export const fetchUsers = createAsyncThunk('users/fetchUsers', async () => {
|
||||||
try {
|
const response = await axios.get(USERS_URL);
|
||||||
const response = await axios.get(USERS_URL);
|
return response.data
|
||||||
return [...response.data];
|
|
||||||
} catch (err) {
|
|
||||||
return err.message;
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
|
|
||||||
const usersSlice = createSlice({
|
const usersSlice = createSlice({
|
||||||
|
@ -11,21 +11,13 @@ const initialState = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export const fetchPosts = createAsyncThunk('posts/fetchPosts', async () => {
|
export const fetchPosts = createAsyncThunk('posts/fetchPosts', async () => {
|
||||||
try {
|
const response = await axios.get(POSTS_URL)
|
||||||
const response = await axios.get(POSTS_URL)
|
return response.data
|
||||||
return [...response.data];
|
|
||||||
} catch (err) {
|
|
||||||
return err.message;
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
|
|
||||||
export const addNewPost = createAsyncThunk('posts/addNewPost', async (initialPost) => {
|
export const addNewPost = createAsyncThunk('posts/addNewPost', async (initialPost) => {
|
||||||
try {
|
const response = await axios.post(POSTS_URL, initialPost)
|
||||||
const response = await axios.post(POSTS_URL, initialPost)
|
return response.data
|
||||||
return response.data
|
|
||||||
} catch (err) {
|
|
||||||
return err.message;
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
|
|
||||||
const postsSlice = createSlice({
|
const postsSlice = createSlice({
|
||||||
|
@ -6,12 +6,8 @@ const USERS_URL = 'https://jsonplaceholder.typicode.com/users';
|
|||||||
const initialState = []
|
const initialState = []
|
||||||
|
|
||||||
export const fetchUsers = createAsyncThunk('users/fetchUsers', async () => {
|
export const fetchUsers = createAsyncThunk('users/fetchUsers', async () => {
|
||||||
try {
|
const response = await axios.get(USERS_URL);
|
||||||
const response = await axios.get(USERS_URL);
|
return response.data
|
||||||
return [...response.data];
|
|
||||||
} catch (err) {
|
|
||||||
return err.message;
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
|
|
||||||
const usersSlice = createSlice({
|
const usersSlice = createSlice({
|
||||||
|
Loading…
x
Reference in New Issue
Block a user