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 () => {
|
||||
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({
|
||||
|
@ -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({
|
||||
|
@ -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) => {
|
||||
|
@ -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({
|
||||
|
@ -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({
|
||||
|
@ -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({
|
||||
|
Loading…
x
Reference in New Issue
Block a user