Add ConflictException

This commit is contained in:
philipp lang 2023-02-08 01:39:32 +01:00
parent 5908568877
commit 1359721d67
3 changed files with 15 additions and 11 deletions

View File

@ -16,6 +16,7 @@ use Zoomyboy\LaravelNami\Data\Member;
use Zoomyboy\LaravelNami\Data\MemberEntry;
use Zoomyboy\LaravelNami\Data\Membership;
use Zoomyboy\LaravelNami\Data\MembershipEntry;
use Zoomyboy\LaravelNami\Exceptions\ConflictException;
use Zoomyboy\LaravelNami\Exceptions\HttpException;
use Zoomyboy\LaravelNami\Exceptions\MemberDataCorruptedException;
use Zoomyboy\LaravelNami\Exceptions\NoJsonReceivedException;
@ -126,9 +127,7 @@ class Api
$payload['kontoverbindung'] = json_encode(data_get($payload, 'kontoverbindung', []));
$url = $this->url.'/ica/rest/nami/mitglied/filtered-for-navigation/gruppierung/gruppierung/'.$member->groupId.'/'.$member->id;
$response = $this->http()->put($url, $payload);
if (true !== data_get($response->json(), 'success')) {
$this->exception(NotSuccessfulException::class, 'Update failed', $url, $response->json(), $member->toNami());
}
$this->assertOk($response, $url, 'Update failed');
return $response->json()['data']['id'];
} else {
@ -480,6 +479,10 @@ class Api
$this->exception(RightException::class, $error, $url, $response->json());
}
if (data_get($response, 'message') && Str::contains($response['message'], 'Der Datensatz wurde zwischenzeitlich verändert')) {
$this->exception(ConflictException::class, $error, $url, $response->json());
}
if (false === $response['success']) {
$this->exception(NotSuccessfulException::class, $error, $url, $response->json());
}

View File

@ -0,0 +1,7 @@
<?php
namespace Zoomyboy\LaravelNami\Exceptions;
class ConflictException extends HttpException
{
}

View File

@ -4,7 +4,6 @@ namespace Zoomyboy\LaravelNami\Exceptions;
use Exception;
use Illuminate\Console\Command;
use Illuminate\Support\Str;
use Illuminate\Validation\ValidationException;
abstract class HttpException extends Exception
@ -54,9 +53,9 @@ abstract class HttpException extends Exception
return $this;
}
public function isConflict(): bool
public function render(): void
{
return Str::contains(data_get($this->response, 'message'), 'Der Datensatz wurde zwischenzeitlich verändert');
throw ValidationException::withMessages(['id' => 'Unbekannter Fehler']);
}
public function report(): void
@ -68,11 +67,6 @@ abstract class HttpException extends Exception
]);
}
public function render(): void
{
throw ValidationException::withMessages(['id' => 'Unbekannter Fehler']);
}
public function outputToConsole(Command $command): void
{
$command->info('Request URL: '.$this->requestUrl);