-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Change value returned when fail to get weather data to Error from str…
…ing and Modify error in toolkit.ts
- Loading branch information
1 parent
f33364d
commit 1fd1fb4
Showing
5 changed files
with
56 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,25 @@ | ||
import {call, put, takeEvery} from 'redux-saga/effects'; | ||
import { call, put, takeEvery } from "redux-saga/effects"; | ||
import { getWeatherData } from "../api"; | ||
import { WeatherState } from "./types"; | ||
import { request, success, failure } from "./reducer"; | ||
|
||
function* getWeatherSaga(action:ReturnType<typeof request>){ | ||
const {longitude, latitude,sfGrid} =action.payload ; | ||
function* getWeatherSaga(action: ReturnType<typeof request>) { | ||
const { longitude, latitude, sfGrid } = action.payload; | ||
try { | ||
const data : string|WeatherState = yield call(()=>(getWeatherData(sfGrid, longitude, latitude))); | ||
if(typeof data === "string"){ | ||
const error =new Error(data); | ||
yield put(failure(error)); | ||
}else{ | ||
yield put(success(data)) | ||
}; | ||
const data: Error | WeatherState = yield call(() => | ||
getWeatherData(sfGrid, longitude, latitude) | ||
); | ||
if (data instanceof Error) { | ||
yield put(failure(data)); | ||
} else { | ||
yield put(success(data)); | ||
} | ||
} catch (error) { | ||
const e = new Error(`Can't get weather data ${error}`); | ||
yield put(failure(e)); | ||
} | ||
}; | ||
} | ||
|
||
export function* weatherSaga( ){ | ||
yield takeEvery(request, getWeatherSaga) | ||
}; | ||
export function* weatherSaga() { | ||
yield takeEvery(request, getWeatherSaga); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters