Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 65a7ed1

Browse files
josip-miloticJosip Milotić
and
Josip Milotić
authored
Throw exception on failed request, extracted fetching headers to separate method to make overrideable (#82)
Co-authored-by: Josip Milotić <josip.milotic@asseco-see.hr>
1 parent 10ab2d5 commit 65a7ed1

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

‎src/App/Http/Controllers/RemoteCustomFieldController.php‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ public function resolveByIdentifierValue(RemoteType $remoteType, string $identif
126126

127127
$data = collect($data)->where($remoteType->identifier_property, $identifierValue)->first();
128128

129-
$transformed = $this->mapSingle($remoteType->mappings, $data);
129+
$transformed = is_array($data) ? $this->mapSingle($remoteType->mappings, $data) : $data;
130130

131131
return response()->json($transformed);
132132
}

‎src/App/Models/RemoteType.php‎

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,12 +52,17 @@ public function getRemoteData()
5252
return Cache::get($cacheKey);
5353
}
5454

55-
$response = Http::withHeaders($this->headers ?: [])
55+
$response = Http::withHeaders($this->getHeaders() ?: [])
5656
->withBody($this->body, 'application/json')
57-
->{$this->method}($this->url)->json();
57+
->{$this->method}($this->url)->throw()->json();
5858

5959
Cache::put($cacheKey, $response, config('asseco-custom-fields.remote_cache_ttl'));
6060

6161
return $response;
6262
}
63+
64+
protected function getHeaders()
65+
{
66+
return $this->headers;
67+
}
6368
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /