mirror of
https://github.com/immich-app/immich.git
synced 2026-05-13 02:58:25 -04:00
* refactor(server)!: structured validation error responses * refactor(server): clarify comment on removing duplicate HTTP response fields * enhance validation error tests * make path and message required * fmt * fix e2e test * fmt * feat: enhance error handling in getServerErrorMessage function
42 lines
1.1 KiB
TypeScript
42 lines
1.1 KiB
TypeScript
import { expect } from 'vitest';
|
|
|
|
export const errorDto = {
|
|
unauthorized: {
|
|
message: 'Authentication required',
|
|
},
|
|
forbidden: {
|
|
message: expect.any(String),
|
|
},
|
|
missingPermission: (permission: string) => ({
|
|
message: `Missing required permission: ${permission}`,
|
|
}),
|
|
wrongPassword: {
|
|
message: 'Wrong password',
|
|
},
|
|
invalidToken: {
|
|
message: 'Invalid user token',
|
|
},
|
|
invalidShareKey: {
|
|
message: 'Invalid share key',
|
|
},
|
|
invalidSharePassword: {
|
|
message: 'Invalid password',
|
|
},
|
|
badRequest: (message: any = null) => ({
|
|
message: message ?? expect.anything(),
|
|
}),
|
|
validationError: (errors?: ReadonlyArray<{ path: ReadonlyArray<string | number>; message: string }>) => ({
|
|
message: 'Validation failed',
|
|
errors: errors ? expect.arrayContaining(errors.map((e) => expect.objectContaining(e))) : expect.any(Array),
|
|
}),
|
|
noPermission: {
|
|
message: expect.stringContaining('Not found or no'),
|
|
},
|
|
incorrectLogin: {
|
|
message: 'Incorrect email or password',
|
|
},
|
|
alreadyHasAdmin: {
|
|
message: 'The server already has an admin',
|
|
},
|
|
};
|