diff --git a/package.json b/package.json index 405bafe..709ba20 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "quirons-broker", - "version": "0.0.1-alpha.116", + "version": "0.0.1-alpha.117", "description": "A small library to expose the broker types", "main": "index.ts", "typings": "index.d.ts", diff --git a/src/errors.ts b/src/errors.ts index ba2b172..d629da1 100644 --- a/src/errors.ts +++ b/src/errors.ts @@ -2,11 +2,11 @@ import { Either } from 'fp-ts/lib/Either' import * as t from 'io-ts' import { PathReporter } from 'io-ts/lib/PathReporter' -const Language = t.union([ +export const Language = t.union([ t.literal('en-US'), t.literal('pt-BR') ]) -type Language = t.TypeOf +export type Language = t.TypeOf // Recomendation of io-ts docs to create an union of literal strings const ErrorCodeKey = t.keyof({ @@ -206,11 +206,16 @@ const raiseErrorFromDecode = ( for (let index = 0; index < errors.length; index++) { const error = errors[index] const message = left.length >= index ? left[index].message : undefined + const value = left.length >= index ? left[index].value : undefined // 'Invalid value undefined supplied to... /id: string' // It will match 'id' and 'string' if (message) { - attributes.push(message) + attributes.push( + value + ? `${message} - ${value}` + : message + ) } else { const [, attribute, type] = error.match(/.+\/(.+): (.+)$/) || [] @@ -223,7 +228,11 @@ const raiseErrorFromDecode = ( continue } - attributes.push(`(${attribute}: ${type})`) + attributes.push( + value + ? `(${attribute}: ${type}) - ${value}` + : `(${attribute}: ${type})` + ) } } diff --git a/src/esocial/messages.ts b/src/esocial/messages.ts index fd47bcc..e7f390a 100644 --- a/src/esocial/messages.ts +++ b/src/esocial/messages.ts @@ -89,7 +89,7 @@ export const Message = t.union([ ])), t.type({ // This should match the tag above - kind: t.literal('responseTAF'), + kind: t.literal('responseGov'), errorMessage: t.string }) ]) diff --git a/src/ttalk/internal/occupation.ts b/src/ttalk/internal/occupation.ts index 0d42cb1..09a2d52 100644 --- a/src/ttalk/internal/occupation.ts +++ b/src/ttalk/internal/occupation.ts @@ -2,7 +2,7 @@ import * as t from 'io-ts' import * as ttalk from '../' import { cbo, datetime, nullable } from '../../custom-types' -import { raiseErrorFromDecode } from '../../errors' +import { raiseErrorFromDecode, Language } from '../../errors' /** * Our internal model for occupations. @@ -31,11 +31,14 @@ export type Positions = t.TypeOf * Standard message converter. */ export const Converter = { - fromTTalk(data: ttalk.PositionInfo): Positions { + fromTTalk( + data: ttalk.PositionInfo, + language: Language = 'en-US' + ): Positions { const result = ttalk.PositionInfo.decode(data) if (result._tag === 'Left') { - throw raiseErrorFromDecode(result) + throw raiseErrorFromDecode(result, language) } return {