Skip to content

Commit

Permalink
Merge pull request #307 from amplimindcc/306-improve-error-handling-o…
Browse files Browse the repository at this point in the history
…n-commit-pag

add handling for 503 and 413
  • Loading branch information
SrNski authored Jun 9, 2024
2 parents e0237c0 + b0d7138 commit 6335477
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 3 deletions.
3 changes: 2 additions & 1 deletion src/locales/de/userProject.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,6 @@
"errorAlreadySubmitted": "Sie haben bereits eine Lösung für diese Challenge eingereicht. Wenn Sie denken, dass dies ein Fehler ist, kontaktieren Sie uns bitte.",
"errorZIPBombDetected": "Der Inhalt der ZIP Datei, die sie hochgeladen haben übersteigt die maximale Größe von 100MB oder enthält weitere ZIP Dateien.",
"errorZIPFileTooLarge": "Die ZIP Datei, die sie hochgeladen haben übersteigt die maximale Größe von 100MB.",
"linterResult": "Dein Linting Ergebnis"
"linterResult": "Dein Linting Ergebnis",
"errorServerConfig": "Serverkonfigurationsfehler. Bitte kontaktieren Sie einen Administrator."
}
3 changes: 2 additions & 1 deletion src/locales/en/userProject.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,6 @@
"errorAlreadySubmitted": "You have already submitted this challenge. If you think this is an error, please contact us.",
"errorZIPBombDetected": "Your ZIP files content exceeds 100MB or contains nested ZIP files.",
"errorZIPFileTooLarge": "Your ZIP file exceeds the maximum size of 100MB.",
"linterResult": "Your linting result"
"linterResult": "Your linting result",
"errorServerConfig": "Server configuration error. Please contact an admin."
}
32 changes: 32 additions & 0 deletions src/pages/Commit/Commit.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -399,6 +399,38 @@ describe('Commit', () => {
);
await user.click(uploadButton);

await screen.findByText(/Server configuration error/i);
});

test('zip file too large', async () => {
server.use(
http.post(`${baseURL}/v1/submission/submit`, () => {
return new HttpResponse(null, {
status: StatusCodes.REQUEST_TOO_LONG,
});
})
);

renderCommit();

const languageInput = await screen.findByLabelText(
/programming language\s*\*:/i
);
const versionInput = await screen.findByLabelText(/version\s*\*:/i);
const fileUploadInput = await screen.findByTestId('fileUpload');
const uploadButton = await screen.findByRole('button', {
name: /upload/i,
});
const user = userEvent.setup();

await user.type(languageInput, 'testLanguage');
await user.type(versionInput, 'testVersion');
await user.upload(
fileUploadInput,
new File(['test file'], 'test.zip', { type: 'application/zip' })
);
await user.click(uploadButton);

await screen.findByText(/Your ZIP file exceeds the maximum size/i);
});

Expand Down
6 changes: 5 additions & 1 deletion src/pages/Commit/Commit.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -306,11 +306,15 @@ const Commit = () => {
case StatusCodes.GONE:
toast.showToast(ToastType.ERROR, t('errorSubmissionExpired'));
break;
case StatusCodes.REQUEST_TOO_LONG:
toast.showToast(ToastType.ERROR, t('errorZIPFileTooLarge'));
break;
case StatusCodes.UNPROCESSABLE_ENTITY:
toast.showToast(ToastType.ERROR, t('errorNoREADME'));
break;
case StatusCodes.SERVICE_UNAVAILABLE:
toast.showToast(ToastType.ERROR, t('errorZIPFileTooLarge'));
// if this error occurs check the accessToken in GitHubApiClientConfig.kt
toast.showToast(ToastType.ERROR, t('errorServerConfig'));
break;
default:
toast.showToast(ToastType.ERROR, t('errorSubmissionFailed'));
Expand Down

0 comments on commit 6335477

Please sign in to comment.