quirons-broker
Advanced tools
Comparing version 0.0.1-alpha.110 to 0.0.1-alpha.111
@@ -71,2 +71,5 @@ "use strict"; | ||
(u) => /(\d\d\d\d)-?(\d\.?\d)/.test(u), (u, c) => Either_1.either.chain(t.string.validate(u, c), s => { | ||
if (s.trim() === '') { | ||
return t.success(s); | ||
} | ||
const isValidCBO = /(\d\d\d\d)-?(\d\.?\d)/.test(s); | ||
@@ -73,0 +76,0 @@ return !isValidCBO |
import { Either } from 'fp-ts/lib/Either'; | ||
import * as t from 'io-ts'; | ||
declare type Language = 'en' | 'ptBR'; | ||
declare const Language: t.UnionC<[t.LiteralC<"en-US">, t.LiteralC<"pt-BR">]>; | ||
declare type Language = t.TypeOf<typeof Language>; | ||
declare const ErrorCodeKey: t.KeyofC<{ | ||
@@ -26,8 +27,8 @@ ENTITY_ALREADY_EXIST: null; | ||
declare class APIValidationError extends APIError { | ||
constructor(payload?: string); | ||
constructor(payload?: string, language?: Language); | ||
} | ||
declare class APIBadRequestError extends APIError { | ||
constructor(payload?: string); | ||
constructor(payload?: string, language?: Language); | ||
} | ||
declare const raiseErrorFromDecode: <T>(result: Either<t.Errors, T>, language?: Language) => never; | ||
export { APIError, APIValidationError, APIBadRequestError, ErrorCode, ErrorCodeKey, raiseErrorFromDecode }; |
@@ -25,2 +25,6 @@ "use strict"; | ||
const PathReporter_1 = require("io-ts/lib/PathReporter"); | ||
const Language = t.union([ | ||
t.literal('en-US'), | ||
t.literal('pt-BR') | ||
]); | ||
// Recomendation of io-ts docs to create an union of literal strings | ||
@@ -65,3 +69,3 @@ const ErrorCodeKey = t.keyof({ | ||
const getMessage = (language) => { | ||
if (language === 'ptBR') { | ||
if (language === 'pt-BR') { | ||
return brazilianPortugueseMessages; | ||
@@ -96,3 +100,3 @@ } | ||
}; | ||
if (language === 'ptBR') { | ||
if (language === 'pt-BR') { | ||
return brazilianPortugueseDetailedMessages; | ||
@@ -102,3 +106,3 @@ } | ||
}; | ||
const errorInfoWith = (payload = '', language = 'en') => ({ | ||
const errorInfoWith = (payload = '', language = 'en-US') => ({ | ||
ENTITY_ALREADY_EXIST: { | ||
@@ -156,3 +160,3 @@ status: 400, | ||
class APIError extends Error { | ||
constructor(errorCode, payload = '', language = 'en') { | ||
constructor(errorCode, payload = '', language = 'en-US') { | ||
const { status, message, detailedMessage } = errorInfoWith(payload, language)[errorCode]; | ||
@@ -174,4 +178,4 @@ super(message); | ||
class APIValidationError extends APIError { | ||
constructor(payload) { | ||
super('VALIDATION_ERROR', payload); | ||
constructor(payload, language = 'en-US') { | ||
super('VALIDATION_ERROR', payload, language); | ||
} | ||
@@ -181,8 +185,8 @@ } | ||
class APIBadRequestError extends APIError { | ||
constructor(payload) { | ||
super('BAD_REQUEST', payload); | ||
constructor(payload, language = 'en-US') { | ||
super('BAD_REQUEST', payload, language); | ||
} | ||
} | ||
exports.APIBadRequestError = APIBadRequestError; | ||
const raiseErrorFromDecode = (result, language = 'en') => { | ||
const raiseErrorFromDecode = (result, language = 'en-US') => { | ||
const errors = PathReporter_1.PathReporter.report(result); | ||
@@ -216,3 +220,3 @@ const left = result._tag === 'Left' ? result.left : []; | ||
const es = attributes.length > 1 ? 'es' : ''; | ||
const message = language == 'ptBR' | ||
const message = language == 'pt-BR' | ||
? `Valor${es} inválido${s} ou faltante${s} para o${s} atributo${s}:` | ||
@@ -219,0 +223,0 @@ : `Invalid or missing value${s} for the attribute${s}: ` |
@@ -128,3 +128,5 @@ import * as t from 'io-ts'; | ||
REQUIRED_ID_PARAMETER: null; | ||
BAD_REQUEST: null; | ||
BAD_REQUEST: null; /** | ||
* Which kind of message we're requesting. | ||
*/ | ||
DECODED_ERROR: null; | ||
@@ -131,0 +133,0 @@ TOO_MANY_REQUESTS: null; |
{ | ||
"name": "quirons-broker", | ||
"version": "0.0.1-alpha.110", | ||
"version": "0.0.1-alpha.111", | ||
"description": "A small library to expose the broker types", | ||
@@ -5,0 +5,0 @@ "main": "index.ts", |
1016202
23544