Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add status code to the result of Kitsu.prototype.request. #1041

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions packages/kitsu/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -510,7 +510,7 @@ export default class Kitsu {
async request ({ body, method, params, type, url, headers, axiosOptions }) {
try {
method = method?.toUpperCase() || 'GET'
const { data, headers: responseHeaders } = await this.axios.request({
const { data, headers: responseHeaders, status: responseStatusCode } = await this.axios.request({
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
const { data, headers: responseHeaders, status: responseStatusCode } = await this.axios.request({
const { data, headers: responseHeaders, statusCode: responseStatusCode } = await this.axios.request({

method,
url,
data: [ 'GET', 'DELETE' ].includes(method)
Expand All @@ -524,7 +524,7 @@ export default class Kitsu {
...axiosOptions
})

return responseHeaders ? { ...deserialise(data), ...{ headers: responseHeaders } } : deserialise(data)
return { ...deserialise(data), responseStatusCode, ...(responseHeaders ? { headers: responseHeaders } : {}) }
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
return { ...deserialise(data), responseStatusCode, ...(responseHeaders ? { headers: responseHeaders } : {}) }
return {
...deserialise(data),
statusCode,
...(responseHeaders ? { headers: responseHeaders } : {})
}

} catch (E) {
throw error(E)
}
Expand Down
Loading