Skip to content
This repository was archived by the owner on Jul 6, 2025. It is now read-only.

Commit da3e964

Browse files
committed
return string in PastebinClient.post() and check for userKey in PastebinClient#login()
1 parent b7645c5 commit da3e964

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

src/struct/PastebinClient.js

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,15 @@ module.exports = class PastebinClient {
6262
* Make a POST request to a Pastebin API URL.
6363
* @param {string} url The URL to request
6464
* @param {Object} requestBody The body of the request
65-
* @returns {Object}
65+
* @returns {Promise<string>}
6666
*/
6767
static async post(url, requestBody) {
68+
if (typeof url !== "string")
69+
throw new PastebinError("`url` must be a string.")
70+
if (!new URL(url).protocol.startsWith("http"))
71+
throw new PastebinError("`url` must use the HTTP or HTTPS protocol.")
72+
if (!requestBody || typeof requestBody !== "object")
73+
throw new PastebinError("`requestBody` must be an object.")
6874
const response = await fetch(url, {
6975
method: "POST",
7076
headers: { "Content-Type": "application/x-www-form-urlencoded;charset=UTF-8" },
@@ -108,7 +114,7 @@ module.exports = class PastebinClient {
108114
throw new PastebinError(`Unknown error: ${error}.`)
109115
}
110116
} else {
111-
return { body, error: null }
117+
return body
112118
}
113119
}
114120

@@ -129,7 +135,8 @@ module.exports = class PastebinClient {
129135
})
130136

131137
this.credentials.userKey = body.trim()
132-
this.user = await this.users.fetch(this.credentials.username)
138+
if (this.credentials.userKey)
139+
this.user = await this.users.fetch(this.credentials.username)
133140

134141
return this
135142
}

0 commit comments

Comments
 (0)