error-mapping-java

Error mapping for thrift adapter

License

License

Categories

Categories

Java Languages
GroupId

GroupId

com.rbkmoney
ArtifactId

ArtifactId

error-mapping-java
Last Version

Last Version

1.0.8
Release Date

Release Date

Type

Type

jar
Description

Description

error-mapping-java
Error mapping for thrift adapter
Project URL

Project URL

https://github.com/rbkmoney/error-mapping-java
Source Code Management

Source Code Management

https://github.com/rbkmoney/error-mapping-java/tree/master

Download error-mapping-java

How to add to project

<!-- https://jarcasting.com/artifacts/com.rbkmoney/error-mapping-java/ -->
<dependency>
    <groupId>com.rbkmoney</groupId>
    <artifactId>error-mapping-java</artifactId>
    <version>1.0.8</version>
</dependency>
// https://jarcasting.com/artifacts/com.rbkmoney/error-mapping-java/
implementation 'com.rbkmoney:error-mapping-java:1.0.8'
// https://jarcasting.com/artifacts/com.rbkmoney/error-mapping-java/
implementation ("com.rbkmoney:error-mapping-java:1.0.8")
'com.rbkmoney:error-mapping-java:jar:1.0.8'
<dependency org="com.rbkmoney" name="error-mapping-java" rev="1.0.8">
  <artifact name="error-mapping-java" type="jar" />
</dependency>
@Grapes(
@Grab(group='com.rbkmoney', module='error-mapping-java', version='1.0.8')
)
libraryDependencies += "com.rbkmoney" % "error-mapping-java" % "1.0.8"
[com.rbkmoney/error-mapping-java "1.0.8"]

Dependencies

compile (2)

Group / Artifact Type Version
com.fasterxml.jackson.core : jackson-databind jar 2.11.2
com.fasterxml.jackson.core : jackson-core jar 2.11.2

provided (4)

Group / Artifact Type Version
com.rbkmoney.woody : woody-thrift jar [1.1.21,)
com.rbkmoney : damsel jar 1.439-b18f037
com.rbkmoney.geck : serializer jar [0.6.11,)
org.projectlombok : lombok jar 1.18.8

test (2)

Group / Artifact Type Version
org.slf4j : slf4j-simple jar 1.7.25
junit : junit jar 4.12

Project Modules

There are no modules declared in this project.

Error mapping

Build Status

Маппинг ошибок

Настройки

Добавить в pom.xml в зависимости

<dependency>
    <groupId>com.rbkmoney</groupId>
    <artifactId>error-mapping-java</artifactId>
    <version>${error-mapping-java.version}</version>
</dependency>

и в application.yml

error-mapping:
  file: classpath:fixture/errors.json
  patternReason: "'%s' - '%s'" # 'code' - 'description'

file - путь к файлу с необходимой структурой для маппинга ошибок

patternReason - формат шаблона, по умолчанию '%s' - '%s'

Настройки перед использованием

Добавляем в приложение конфигурационный файл: Если хотим, чтобы при запуске проверялись ошибки на корректность, то добавляем validateMapping()

@Configuration
public class ErrorMappingConfiguration {

    @Value("${error-mapping.file}")
    private Resource filePath;

    @Value("${error-mapping.patternReason:\"'%s' - '%s'\"}")
    private String patternReason;

    @Bean
    ErrorMapping errorMapping() throws IOException {
        ErrorMapping errorMapping = new ErrorMapping(filePath.getInputStream(), patternReason);
        errorMapping.validateMapping();
        return errorMapping;
    }

}

Использование

Подключаем как зависимость

@Autowired
private final ErrorMapping errorMapping;

в коде вызываем:

errorMapping.mapFailure(code)
errorMapping.mapFailure(code, description)
errorMapping.mapFailure(code, description, state)

и получаем трифтовую структуру Failure

Пример структуры файла маппинга ошибок (errors.json)

[
  {
    "codeRegex": "001",
    "mapping": "authorization_failed:operation_blocked"
  },
  {
    "codeRegex":"002",
    "descriptionRegex":"Invalid .*",
    "mapping":"authorization_failed:operation_blocked"
  },
  {
    "codeRegex":"003",
    "descriptionRegex":"Invalid cardholder",
    "mapping":"authorization_failed:operation_blocked",
    "state": "payment"
  },
  {
    "codeRegex":"004",
    "descriptionRegex":"Timeout",
    "mapping":"ResultUnknown"
  }
]

Возможные ошибки:

preauthorization_failed
rejected_by_inspector

authorization_failed:unknown
authorization_failed:merchant_blocked
authorization_failed:operation_blocked
authorization_failed:account_not_found
authorization_failed:account_blocked
authorization_failed:account_stolen
authorization_failed:insufficient_funds

authorization_failed:security_policy_violated
authorization_failed:temporarily_unavailable
authorization_failed:rejected_by_issuer

authorization_failed:account_limit_exceeded:amount
authorization_failed:account_limit_exceeded:number
authorization_failed:account_limit_exceeded:unknown

authorization_failed:provider_limit_exceeded:amount
authorization_failed:provider_limit_exceeded:number
authorization_failed:provider_limit_exceeded:unknown

authorization_failed:payment_tool_rejected:unknown
authorization_failed:payment_tool_rejected:bank_card_rejected:card_expired
authorization_failed:payment_tool_rejected:bank_card_rejected:card_number_invalid
authorization_failed:payment_tool_rejected:bank_card_rejected:card_holder_invalid
authorization_failed:payment_tool_rejected:bank_card_rejected:cvv_invalid
authorization_failed:payment_tool_rejected:bank_card_rejected:card_unsupported
authorization_failed:payment_tool_rejected:bank_card_rejected:issuer_not_found

ResourceUnavailable
ResultUnknown
ResultUnexpected
com.rbkmoney

RBKmoney

Versions

Version
1.0.8
1.0.7
1.0.6