Skip to content

Commit

Permalink
Because we already use axios in other place, let use it here to get c…
Browse files Browse the repository at this point in the history
…onsistent handling of HTTP errors
  • Loading branch information
adrianmroz-allegro committed Sep 21, 2022
1 parent fa08d32 commit ae556e2
Showing 1 changed file with 4 additions and 8 deletions.
12 changes: 4 additions & 8 deletions src/client/modals/url-shortener-modal/url-shortener-modal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import { Modal } from "../../components/modal/modal";
import { SafeCopyToClipboard } from "../../components/safe-copy-to-clipboard/safe-copy-to-clipboard";
import { STRINGS } from "../../config/constants";
import "./url-shortener-modal.scss";
import axios from "axios";

interface UrlShortenerModalProps {
onClose: Fn;
Expand Down Expand Up @@ -59,14 +60,9 @@ export class UrlShortenerPrompt extends React.Component<UrlProp, UrlShortenerPro
}

shortenUrl() {
return fetch("shorten?url=" + encodeURIComponent(this.props.url))
.then(response => {
if (!response.ok) {
throw Error(response.statusText);
}
return response;
})
.then(response => response.json());
// NOTE: When replacing axios, please remember that native fetch doesn't reject on 4xx/5xx errors!
return axios("shorten?url=" + encodeURIComponent(this.props.url))
.then(response => response.data);
}

renderShortUrl() {
Expand Down

0 comments on commit ae556e2

Please sign in to comment.