Merging origin/dev into feat/assignment-page correctie
This commit is contained in:
commit
baea0051e6
249 changed files with 6754 additions and 3612 deletions
14
frontend/src/utils/response-assertions.ts
Normal file
14
frontend/src/utils/response-assertions.ts
Normal file
|
@ -0,0 +1,14 @@
|
|||
import { NotFoundException } from "@/exception/not-found-exception.ts";
|
||||
import { InvalidResponseException } from "@/exception/invalid-response-exception.ts";
|
||||
|
||||
export function single<T>(list: T[]): T {
|
||||
if (list.length === 1) {
|
||||
return list[0];
|
||||
} else if (list.length === 0) {
|
||||
throw new NotFoundException("Expected list with exactly one element, but got an empty list.");
|
||||
} else {
|
||||
throw new InvalidResponseException(
|
||||
`Expected list with exactly one element, but got one with ${list.length} elements.`,
|
||||
);
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue