Commit 22e49db0 authored by Matheus Horstmann's avatar Matheus Horstmann 🐴 Committed by Lucas Fernandes de Oliveira

Issue #17: Add ErrorHandler

Signed-off-by: Matheus Horstmann's avatarMatheus Horstmann <mch15@inf.ufpr.br>
parent 6b2c8af7
......@@ -3,6 +3,13 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
## 0.0.11 - 17-04-2019
### Added
- ErrorHandler to standardize errors message through the project #17 (Horstmann)
### Changed
- TestHandler documentation title
- dbHandler tests to use ErrorHandler #18 (Horstmann)
## 0.0.10 - 16-04-2019
### Added
- TestHandler to test form and inputs #18 (Horstmann)
......@@ -14,7 +21,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- ValidationHandler to receive a string as size instead number as validation arguments
- ValidationHandler to cast size to number
- ValidationHandler tests to use string instead of number as validation arguments
## 0.0.9 - 10-04-2019
### Added
- Method read in Form controller to get a Form
......
{
"name": "form-creator-api",
"version": "0.0.10",
"version": "0.0.11",
"description": "RESTful API used to manage and answer forms.",
"main": "index.js",
"scripts": {
......
......@@ -24,6 +24,7 @@ import { Pool, PoolConfig, QueryResult } from "pg";
import { Form } from "../core/form";
import { Input, Validation } from "../core/input";
import { EnumHandler, InputType, ValidationType } from "./enumHandler";
import { ErrorHandler} from "./errorHandler";
/**
* Class of the SGBD from the Form Creator Api perspective. Used to
......@@ -141,7 +142,7 @@ export class DbHandler {
(result: QueryResult, callback: (err: Error, form?: Form) => void) => {
if (result.rowCount !== 1){
callback(new Error("Bad number of ids returned: found '" + result.rowCount + "' should be 1"));
callback(ErrorHandler.badIdAmount(result.rowCount));
return;
}
this.readInputWithFormId(id, (error: Error, inputs: Input[]) => {
......@@ -312,7 +313,7 @@ export class DbHandler {
},
(result: QueryResult, callback: (err: Error, formId?: number) => void) => {
if (result.rowCount !== 1){
callback(new Error("Form not inserted"));
callback(ErrorHandler.notInserted("Form"));
return;
}
eachSeries(form.inputs, (input: Input, innerCallback) => {
......@@ -374,7 +375,7 @@ export class DbHandler {
}
if (result.rowCount !== 1){
cb(new Error("Input not Inserted"));
cb(ErrorHandler.notInserted("Input"));
return;
}
......@@ -411,7 +412,7 @@ export class DbHandler {
}
if (result.rowCount !== 1){
cb(new Error("Validation not Inserted"));
cb(ErrorHandler.notInserted("Validation"));
return;
}
......@@ -448,7 +449,7 @@ export class DbHandler {
}
if (result.rowCount !== 1){
cb(new Error("Validation Argument not Inserted"));
cb(ErrorHandler.notInserted("Validation Argument"));
return;
}
......
/*
* form-creator-api. RESTful API to manage and answer forms.
* Copyright (C) 2019 Centro de Computacao Cientifica e Software Livre
* Departamento de Informatica - Universidade Federal do Parana - C3SL/UFPR
*
* This file is part of form-creator-api.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
/**
* Error's handler. Manage error message through the project.
*/
export class ErrorHandler {
/**
* Return an error instance with a default message when ids amount is different than 1.
* @param idNumber - Amount of ids found.
* @returns - An error instance with correct message.
*/
public static badIdAmount(idNumber: number): Error{
return new Error("Bad amount of ids returned: found '" + idNumber + "' should be 1");
}
/**
* Return an error instance when a object is not inserted.
* @param objectName - Name of object, usually the name of the table.
* @returns - An error instance with correct message.
*/
public static notInserted(objectName: string): Error{
return new Error(objectName + " not inserted");
}
}
......@@ -25,7 +25,7 @@
import { EnumHandler, InputType, ValidationType } from "./enumHandler";
/**
* Enum's handler. Manage parse through the project.
* Test's handler. Manage tests through the project.
*/
export class TestHandler {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment