MT940.Parser

This module contains functions to parse SWIFT’s MT940 messages.

API

The parse function in this module returns {:ok, result} in case of success, {:error, reason} otherwise. It is also followed by a variant that ends with ! which returns the result (without the {:ok, result} tuple) in case of success or raises an exception in case it fails. For example:

use MT940

parse(":20:TELEWIZORY S.A.")
#=> {:ok, [[":20:": "TELEWIZORY S.A."]]}

parse("invalid")
#=> {:error, :badarg}

parse!(":20:TELEWIZORY S.A.")
#=> [[":20:": "TELEWIZORY S.A."]]

parse!("invalid")
#=> raises ArgumentError

In general, a developer should use the former in case he wants to react if the raw input cannot be parsed. The latter should be used when the developer expects his software to fail in case the raw input cannot be parsed (i.e. it is literally an exception).

Source

Summary

parse!(raw)

Returns list of SWIFT MT940 messages or raises ArgumentError if an error occurs

parse(raw)

Returns {:ok, result}, where result is a list of SWIFT MT940 messages, or {:error, reason} if an error occurs

Functions

parse(raw)

Returns {:ok, result}, where result is a list of SWIFT MT940 messages, or {:error, reason} if an error occurs.

Typical error reasons:

  • :badarg - the format of the raw input is not MT940
Source
parse!(raw)

Returns list of SWIFT MT940 messages or raises ArgumentError if an error occurs.

Source