Ecomailcz / ecomail-php

PHP wrapper pro práci s Ecomail.cz API
12 stars 19 forks source link

Added more info when request failed #25

Closed grogy closed 3 years ago

grogy commented 4 years ago

This PR has not BC break.

Why do it? When user (programmer) send incorrect request than he isn't feedback what is bad. Example:

var_dump($ecoMail->sendTransactionalTemplate([
    'template_id' => 1,
    'to' => [
        'email' => 'customer@domain.tld',
    ],
]));

The current output is:

array(1) {
  ["error"]=>
  int(400)
}

Okey.. something is bad. But what? Incorrect data? Expired account? Something in network? Some else?

Output after small change in this PR:

array(2) {
  ["error"]=>
  int(400)
  ["message"]=>
  string(166) "{"message":["The message field is required."],"message.template_id":["The message.template id field is required."],"message.to":["The message.to field is required."]}"
}

What do you mean? :)

jakubboucek commented 4 years ago

Hi, your idea is great.

I have one issue: You put returned value whole request body as a string only. But usually it will be JSON. Please try add to returned valued Mimetype (content-type header) of response too for better ability to manipulation with returned value.

grogy commented 3 years ago

Hello,

yes, it's possible :)

Changed are implemented in PR, example for try it is:

<?php

require_once __DIR__ . '/vendor/autoload.php';

$ecomail = new Ecomail('secret_token');
var_dump($ecomail->sendTransactionalTemplate([
    'template_id' => 1,
    'to' => [
        'email' => 'customer@domain.tld',
    ],
]));