mirror of
https://github.com/CommunitySolidServer/CommunitySolidServer.git
synced 2024-10-03 14:55:10 +00:00
feat: Return correct status codes for invalid requests
This commit is contained in:
@@ -2,4 +2,7 @@ import type { Operation } from '../../http/Operation';
|
||||
import { AsyncHandler } from '../../util/handlers/AsyncHandler';
|
||||
import type { AccessMode } from './Permissions';
|
||||
|
||||
/**
|
||||
* Extracts all {@link AccessMode}s that are necessary to execute the given {@link Operation}.
|
||||
*/
|
||||
export abstract class ModesExtractor extends AsyncHandler<Operation, Set<AccessMode>> {}
|
||||
|
||||
@@ -6,11 +6,13 @@ import { NotImplementedHttpError } from '../../util/errors/NotImplementedHttpErr
|
||||
import { ModesExtractor } from './ModesExtractor';
|
||||
import { AccessMode } from './Permissions';
|
||||
|
||||
export class SparqlPatchModesExtractor extends ModesExtractor {
|
||||
public async canHandle({ method, body }: Operation): Promise<void> {
|
||||
if (method !== 'PATCH') {
|
||||
throw new NotImplementedHttpError(`Cannot determine permissions of ${method}, only PATCH.`);
|
||||
}
|
||||
/**
|
||||
* Generates permissions for a SPARQL DELETE/INSERT body.
|
||||
* Updates with only an INSERT can be done with just append permissions,
|
||||
* while DELETEs require write permissions as well.
|
||||
*/
|
||||
export class SparqlUpdateModesExtractor extends ModesExtractor {
|
||||
public async canHandle({ body }: Operation): Promise<void> {
|
||||
if (!this.isSparql(body)) {
|
||||
throw new NotImplementedHttpError('Cannot determine permissions of non-SPARQL patches.');
|
||||
}
|
||||
Reference in New Issue
Block a user