fix: Rename UnsupportedHttpError into BadRequestError.

This commit is contained in:
Ruben Verborgh
2020-11-27 10:25:05 +01:00
committed by Joachim Van Herwegen
parent 03ffaaed43
commit af8f1976cd
53 changed files with 177 additions and 171 deletions

View File

@@ -1,5 +1,5 @@
import type { ResourceStore } from '../../storage/ResourceStore';
import { UnsupportedHttpError } from '../../util/errors/UnsupportedHttpError';
import { NotImplementedHttpError } from '../../util/errors/NotImplementedHttpError';
import { ResetResponseDescription } from '../http/response/ResetResponseDescription';
import type { ResponseDescription } from '../http/response/ResponseDescription';
import type { Operation } from './Operation';
@@ -19,7 +19,7 @@ export class DeleteOperationHandler extends OperationHandler {
public async canHandle(input: Operation): Promise<void> {
if (input.method !== 'DELETE') {
throw new UnsupportedHttpError('This handler only supports DELETE operations');
throw new NotImplementedHttpError('This handler only supports DELETE operations');
}
}

View File

@@ -1,5 +1,5 @@
import type { ResourceStore } from '../../storage/ResourceStore';
import { UnsupportedHttpError } from '../../util/errors/UnsupportedHttpError';
import { NotImplementedHttpError } from '../../util/errors/NotImplementedHttpError';
import { OkResponseDescription } from '../http/response/OkResponseDescription';
import type { ResponseDescription } from '../http/response/ResponseDescription';
import type { Operation } from './Operation';
@@ -19,7 +19,7 @@ export class GetOperationHandler extends OperationHandler {
public async canHandle(input: Operation): Promise<void> {
if (input.method !== 'GET') {
throw new UnsupportedHttpError('This handler only supports GET operations');
throw new NotImplementedHttpError('This handler only supports GET operations');
}
}

View File

@@ -1,5 +1,5 @@
import type { ResourceStore } from '../../storage/ResourceStore';
import { UnsupportedHttpError } from '../../util/errors/UnsupportedHttpError';
import { NotImplementedHttpError } from '../../util/errors/NotImplementedHttpError';
import { OkResponseDescription } from '../http/response/OkResponseDescription';
import type { ResponseDescription } from '../http/response/ResponseDescription';
import type { Operation } from './Operation';
@@ -19,7 +19,7 @@ export class HeadOperationHandler extends OperationHandler {
public async canHandle(input: Operation): Promise<void> {
if (input.method !== 'HEAD') {
throw new UnsupportedHttpError('This handler only supports HEAD operations');
throw new NotImplementedHttpError('This handler only supports HEAD operations');
}
}

View File

@@ -1,5 +1,5 @@
import type { ResourceStore } from '../../storage/ResourceStore';
import { UnsupportedHttpError } from '../../util/errors/UnsupportedHttpError';
import { NotImplementedHttpError } from '../../util/errors/NotImplementedHttpError';
import type { Patch } from '../http/Patch';
import { ResetResponseDescription } from '../http/response/ResetResponseDescription';
import type { ResponseDescription } from '../http/response/ResponseDescription';
@@ -16,7 +16,7 @@ export class PatchOperationHandler extends OperationHandler {
public async canHandle(input: Operation): Promise<void> {
if (input.method !== 'PATCH') {
throw new UnsupportedHttpError('This handler only supports PATCH operations.');
throw new NotImplementedHttpError('This handler only supports PATCH operations.');
}
}

View File

@@ -1,6 +1,7 @@
import { getLoggerFor } from '../../logging/LogUtil';
import type { ResourceStore } from '../../storage/ResourceStore';
import { UnsupportedHttpError } from '../../util/errors/UnsupportedHttpError';
import { BadRequestHttpError } from '../../util/errors/BadRequestHttpError';
import { NotImplementedHttpError } from '../../util/errors/NotImplementedHttpError';
import { CreatedResponseDescription } from '../http/response/CreatedResponseDescription';
import type { ResponseDescription } from '../http/response/ResponseDescription';
import type { Operation } from './Operation';
@@ -22,14 +23,14 @@ export class PostOperationHandler extends OperationHandler {
public async canHandle(input: Operation): Promise<void> {
if (input.method !== 'POST') {
throw new UnsupportedHttpError('This handler only supports POST operations');
throw new NotImplementedHttpError('This handler only supports POST operations');
}
}
public async handle(input: Operation): Promise<ResponseDescription> {
if (!input.body) {
this.logger.warn('POST operations require a body');
throw new UnsupportedHttpError('POST operations require a body');
throw new BadRequestHttpError('POST operations require a body');
}
const identifier = await this.store.addResource(input.target, input.body);
return new CreatedResponseDescription(identifier);

View File

@@ -1,6 +1,7 @@
import { getLoggerFor } from '../../logging/LogUtil';
import type { ResourceStore } from '../../storage/ResourceStore';
import { UnsupportedHttpError } from '../../util/errors/UnsupportedHttpError';
import { BadRequestHttpError } from '../../util/errors/BadRequestHttpError';
import { NotImplementedHttpError } from '../../util/errors/NotImplementedHttpError';
import { ResetResponseDescription } from '../http/response/ResetResponseDescription';
import type { ResponseDescription } from '../http/response/ResponseDescription';
import type { Operation } from './Operation';
@@ -22,14 +23,14 @@ export class PutOperationHandler extends OperationHandler {
public async canHandle(input: Operation): Promise<void> {
if (input.method !== 'PUT') {
throw new UnsupportedHttpError('This handler only supports PUT operations');
throw new NotImplementedHttpError('This handler only supports PUT operations');
}
}
public async handle(input: Operation): Promise<ResponseDescription> {
if (typeof input.body !== 'object') {
this.logger.warn('No body specified on PUT request');
throw new UnsupportedHttpError('PUT operations require a body');
throw new BadRequestHttpError('PUT operations require a body');
}
await this.store.setRepresentation(input.target, input.body);
return new ResetResponseDescription();