Skip to content

Commit 1885a4d

Browse files
fix(bitly-shortener): Fix 406 HTTP error code from Bit.ly API due to "Content-Type" not being set. (#202)
1 parent 4639a63 commit 1885a4d

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

firestore-shorten-urls-bitly/functions/lib/index.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ class FirestoreBitlyUrlShortener extends abstract_shortener_1.FirestoreUrlShorte
3434
this.instance = axios_1.default.create({
3535
headers: {
3636
Authorization: `Bearer ${bitlyAccessToken}`,
37+
"Content-Type": "application/json",
3738
},
3839
baseURL: "https://api-ssl.bitly.com/v4/",
3940
});
@@ -47,7 +48,7 @@ class FirestoreBitlyUrlShortener extends abstract_shortener_1.FirestoreUrlShorte
4748
const response = yield this.instance.post("bitlinks", {
4849
long_url: url,
4950
});
50-
const { link } = response;
51+
const { link } = response.data;
5152
logs.shortenUrlComplete(link);
5253
yield this.updateShortUrl(snapshot, link);
5354
}

firestore-shorten-urls-bitly/functions/src/index.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,11 @@ class FirestoreBitlyUrlShortener extends FirestoreUrlShortener {
3434
this.instance = axios.create({
3535
headers: {
3636
Authorization: `Bearer ${bitlyAccessToken}`,
37+
"Content-Type": "application/json",
3738
},
3839
baseURL: "https://api-ssl.bitly.com/v4/",
3940
});
41+
4042
logs.init();
4143
}
4244

@@ -51,7 +53,7 @@ class FirestoreBitlyUrlShortener extends FirestoreUrlShortener {
5153
long_url: url,
5254
});
5355

54-
const { link } = response;
56+
const { link } = response.data;
5557

5658
logs.shortenUrlComplete(link);
5759

0 commit comments

Comments
 (0)