Skip to content

Instantly share code, notes, and snippets.

@zaetrik
Created April 19, 2020 10:47
Show Gist options
  • Save zaetrik/df85855ca06da98f51e368163b650753 to your computer and use it in GitHub Desktop.
Save zaetrik/df85855ca06da98f51e368163b650753 to your computer and use it in GitHub Desktop.
Functional JS API Requests - Validating the API Response
const validateExchangeRates = (countryCode: CountryCode) => (
response: ExchangeRates
): either.Either<Error, ExchangeRates> => {
return response.base === countryCode
? either.right(response as ExchangeRates)
: either.left(
Error(
`Invalid exchange rates data! Expected ${countryCode} but got ${response.base}`
)
);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment