Skip to content

Commit

Permalink
feat: Adiciona um log quando a requisição falhar (#201)
Browse files Browse the repository at this point in the history
  • Loading branch information
JoaoPedro0000 authored Nov 4, 2024
1 parent 73979c6 commit 1fdca21
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 7 deletions.
2 changes: 1 addition & 1 deletion Models/Version.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@

class Version {

const VERSION = '2.15.7';
const VERSION = '2.15.8';
}
19 changes: 16 additions & 3 deletions Services/RequestService.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,9 @@

namespace MelhorEnvio\Services;

use MelhorEnvio\Services\ManageRequestService;
use MelhorEnvio\Services\ClearDataStored;
use MelhorEnvio\Models\Version;
use MelhorEnvio\Models\ResponseStatus;
use MelhorEnvio\Services\SessionNoticeService;
use WC_Logger;

class RequestService {

Expand Down Expand Up @@ -76,6 +74,7 @@ public function request( $route, $typeRequest, $body, $useJson = true ) {

if ( ! is_array( $responseRemote ) ) {
if ( get_class( $responseRemote ) === self::WP_ERROR ) {
$this->logErrors($route, $typeRequest, $body, $responseRemote, 000);
return (object) array();
}
}
Expand Down Expand Up @@ -109,6 +108,8 @@ public function request( $route, $typeRequest, $body, $useJson = true ) {
}

if ( ! empty( $response->message ) && $response->message == 'Unauthenticated.' ) {
$this->logErrors($route, $typeRequest, $body, $response, $responseCode);

return (object) array(
'success' => false,
'errors' => array( 'Usuário não autenticado' ),
Expand All @@ -118,6 +119,8 @@ public function request( $route, $typeRequest, $body, $useJson = true ) {
$errors = $this->treatmentErrors( $response );

if ( ! empty( $errors ) ) {
$this->logErrors($route, $typeRequest, $body, $response, $responseCode);

return (object) array(
'success' => false,
'errors' => $errors,
Expand All @@ -127,6 +130,16 @@ public function request( $route, $typeRequest, $body, $useJson = true ) {
return $response;
}

private function logErrors($route, $typeRequest, $body, $response, $responseCode)
{
(new \WC_Logger)->log('error', 'RequestService - CODE '.$responseCode, array(
'route' => $route,
'typeRequest' => $typeRequest,
'body' => $body,
'response' => $response,
));
}

/**
* treatment errors to user
*
Expand Down
2 changes: 1 addition & 1 deletion melhor-envio-beta.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
Plugin Name: Melhor Envio
Plugin URI: https://melhorenvio.com.br
Description: Plugin para cotação e compra de fretes utilizando a API da Melhor Envio.
Version: 2.15.7
Version: 2.15.8
Author: Melhor Envio
Author URI: melhorenvio.com.br
License: GPL2
Expand Down
7 changes: 5 additions & 2 deletions readme.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
=== Melhor Envio ===
Version: 2.15.7
Version: 2.15.8
Tags: frete, fretes, cotação, cotações, correios, envio, jadlog, latam latam cargo, azul, azul cargo express, melhor envio
Requires at least: 4.7
Tested up to: 6.5
Stable tag: 2.15.7
Stable tag: 2.15.8
Requires PHP: 7.2+
Requires Wordpress 4.0+
Requires WooCommerce 4.0+
Expand Down Expand Up @@ -68,6 +68,9 @@ Observação: Atenção com as medidas de unidades utilizadas, cuidado se você
Pronto! o plugin do Melhor Envio está funcionando.

== Changelog ==
= 2.15.8 =
* Adiciona log no caso de falha em uma requisição.

= 2.15.7 =
* Corrige problema na busca do CEP.

Expand Down

0 comments on commit 1fdca21

Please sign in to comment.