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

admin/upgrade-axios-0.28.0 #167

Merged
Merged
Show file tree
Hide file tree
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
13 changes: 11 additions & 2 deletions features/app/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,18 @@ axiosRetry(axiosClient, {
if (error.response) {
const retryAfter = error.response.headers["retry-after"]
if (retryAfter) {
return retryAfter
const retryAfterSeconds = parseInt(retryAfter.trim(), 10)
if (!isNaN(retryAfterSeconds)) {
return retryAfterSeconds * 1000
}
const retryAfterDate = Date.parse(retryAfter.trim())
if (!isNaN(retryAfterDate)) {
const currentTime = Date.now()
const delay = Math.max(retryAfterDate - currentTime, 0)
return delay
}
}
if (error.response.status === 429 && error.config.url?.includes(HYPOTHESIS_API_BASE_URL)) {
if (error.response.status === 429 && error.config?.url?.includes(HYPOTHESIS_API_BASE_URL)) {
return retryCount * 2000 /** ms */
}
}
Expand Down
15 changes: 11 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
"@prisma/client": "^2.27.0",
"@types/carbon-components-react": "^7.44.0",
"@types/carbon__icons-react": "^10.31.2",
"axios": "^0.21.4",
"axios": "^0.28.0",
"axios-retry": "^3.2.4",
"carbon-components": "^10.45.0",
"carbon-components-react": "^7.45.0",
Expand Down
4 changes: 2 additions & 2 deletions pages/api/arcore/[id]/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
try {
await axiosClient.put(`${process.env.ARCORE_SERVER_URL}/api/documents/${id}`, undefined, {
headers: {
[DATAVERSE_HEADER_NAME]: dataverseApiToken,
[DATAVERSE_HEADER_NAME]: dataverseApiToken as string,
[REQUEST_DESC_HEADER_NAME]: `Creating ingest PDF and extracting annotations from source manuscript ${id}`,
},
})
Expand All @@ -29,7 +29,7 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
`${process.env.ARCORE_SERVER_URL}/api/documents/${id}/ann`,
{
headers: {
[DATAVERSE_HEADER_NAME]: dataverseApiToken,
[DATAVERSE_HEADER_NAME]: dataverseApiToken as string,
[REQUEST_DESC_HEADER_NAME]: `Getting annotations from source manuscript ${id}`,
},
}
Expand Down
2 changes: 1 addition & 1 deletion pages/api/datasets/[id]/annorep/delete.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
},
headers: {
"Content-Type": "application/json-ld", //TODO: change ld+json?
[DATAVERSE_HEADER_NAME]: session.dataverseApiToken,
[DATAVERSE_HEADER_NAME]: session.dataverseApiToken as string,
[REQUEST_DESC_HEADER_NAME]: requestDesc,
},
})
Expand Down
2 changes: 1 addition & 1 deletion pages/api/datasets/[id]/annorep/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
},
headers: {
"Content-Type": "application/json-ld", //TODO: change ld+json?
[DATAVERSE_HEADER_NAME]: session.dataverseApiToken,
[DATAVERSE_HEADER_NAME]: session.dataverseApiToken as string,
[REQUEST_DESC_HEADER_NAME]: requestDesc,
},
})
Expand Down
2 changes: 1 addition & 1 deletion pages/api/datasets/[id]/data-files.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
method: "GET",
url: `${process.env.DATAVERSE_SERVER_URL}/api/datasets/${id}`,
headers: {
[DATAVERSE_HEADER_NAME]: session.dataverseApiToken,
[DATAVERSE_HEADER_NAME]: session.dataverseApiToken as string,
[REQUEST_DESC_HEADER_NAME]: requestDesc,
},
})
Expand Down
2 changes: 1 addition & 1 deletion pages/api/datasets/[id]/manuscript/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
data: addManuscriptForm,
headers: {
"Content-Type": `${addManuscriptForm.getHeaders()["content-type"]}`,
[DATAVERSE_HEADER_NAME]: dataverseApiToken,
[DATAVERSE_HEADER_NAME]: dataverseApiToken as string,
[REQUEST_DESC_HEADER_NAME]: requestDesc,
},
})
Expand Down
2 changes: 1 addition & 1 deletion pages/api/datasets/[id]/submit-for-review.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
method: "POST",
url: `${process.env.DATAVERSE_SERVER_URL}/api/datasets/${id}/submitForReview`,
headers: {
[DATAVERSE_HEADER_NAME]: session.dataverseApiToken,
[DATAVERSE_HEADER_NAME]: session.dataverseApiToken as string,
[REQUEST_DESC_HEADER_NAME]: requestDesc,
},
})
Expand Down
2 changes: 1 addition & 1 deletion pages/api/hypothesis/[id]/title-annotation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
`${process.env.ARCORE_SERVER_URL}/api/documents/${manuscriptId}/titleann`,
{
headers: {
[DATAVERSE_HEADER_NAME]: dataverseApiToken,
[DATAVERSE_HEADER_NAME]: dataverseApiToken as string,
[REQUEST_DESC_HEADER_NAME]: `Getting title annotation from source manuscript ${manuscriptId}`,
Accept: "application/json",
},
Expand Down
4 changes: 2 additions & 2 deletions pages/ati/[id]/exportAnnotations.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ export const getServerSideProps: GetServerSideProps = async (context) => {
await axiosClient
.get(`${process.env.DATAVERSE_SERVER_URL}/api/datasets/${datasetId}`, {
headers: {
[DATAVERSE_HEADER_NAME]: dataverseApiToken,
[DATAVERSE_HEADER_NAME]: dataverseApiToken as string,
[REQUEST_DESC_HEADER_NAME]: `Getting JSON for data project ${datasetId}`,
Accept: "application/json",
},
Expand All @@ -108,7 +108,7 @@ export const getServerSideProps: GetServerSideProps = async (context) => {
{
responseType: "arraybuffer",
headers: {
[DATAVERSE_HEADER_NAME]: dataverseApiToken,
[DATAVERSE_HEADER_NAME]: dataverseApiToken as string,
Accept: "application/pdf",
},
}
Expand Down
4 changes: 2 additions & 2 deletions pages/ati/[id]/manuscript.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ export const getServerSideProps: GetServerSideProps = async (context) => {
await axiosClient
.get(`${process.env.DATAVERSE_SERVER_URL}/api/datasets/${datasetId}`, {
headers: {
[DATAVERSE_HEADER_NAME]: dataverseApiToken,
[DATAVERSE_HEADER_NAME]: dataverseApiToken as string,
[REQUEST_DESC_HEADER_NAME]: `Getting JSON for data project ${datasetId}`,
Accept: "application/json",
},
Expand All @@ -89,7 +89,7 @@ export const getServerSideProps: GetServerSideProps = async (context) => {
{
responseType: "arraybuffer",
headers: {
[DATAVERSE_HEADER_NAME]: dataverseApiToken,
[DATAVERSE_HEADER_NAME]: dataverseApiToken as string,
Accept: "application/pdf",
},
}
Expand Down
2 changes: 1 addition & 1 deletion pages/ati/[id]/settings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ export const getServerSideProps: GetServerSideProps = async (context) => {
await axios
.get(`${process.env.DATAVERSE_SERVER_URL}/api/datasets/${datasetId}`, {
headers: {
[DATAVERSE_HEADER_NAME]: dataverseApiToken,
[DATAVERSE_HEADER_NAME]: dataverseApiToken as string,
[REQUEST_DESC_HEADER_NAME]: `Getting JSON for data project ${datasetId}`,
Accept: "application/json",
},
Expand Down
2 changes: 1 addition & 1 deletion pages/ati/[id]/summary.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ export const getServerSideProps: GetServerSideProps = async (context) => {
await axiosClient
.get(`${process.env.DATAVERSE_SERVER_URL}/api/datasets/${datasetId}`, {
headers: {
[DATAVERSE_HEADER_NAME]: dataverseApiToken,
[DATAVERSE_HEADER_NAME]: dataverseApiToken as string,
[REQUEST_DESC_HEADER_NAME]: `Getting JSON for data project ${datasetId}`,
Accept: "application/json",
},
Expand Down
12 changes: 8 additions & 4 deletions utils/httpRequestUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,14 @@ import { AnnoRepResponse } from "../types/http"
export const getResponseFromError = (e: unknown, requestDesc?: string): AnnoRepResponse => {
const annoRepResponse: AnnoRepResponse = { status: 400, message: "" }
if (axios.isAxiosError(e)) {
const requestInfo =
e.config.headers[REQUEST_DESC_HEADER_NAME] ||
requestDesc ||
`${e.config.method} ${e.config.url}`
let requestInfo = "Request"
if (e.config && e.config.headers && e.config.headers[REQUEST_DESC_HEADER_NAME]) {
requestInfo = e.config.headers[REQUEST_DESC_HEADER_NAME] as string
} else if (requestDesc) {
requestInfo = requestDesc
} else if (e.config && e.config.method && e.config.url) {
requestInfo = `${e.config.method} ${e.config.url}`
}
let failureMessage = `${requestInfo} failed.`
if (e.response) {
const additional =
Expand Down
Loading