Skip to content

Commit 4575b76

Browse files
committed
chore: update changelog and docs
Signed-off-by: David Adi Nugroho <[email protected]>
1 parent d112054 commit 4575b76

File tree

3 files changed

+24
-16
lines changed

3 files changed

+24
-16
lines changed

CHANGELOG.md

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,18 @@
22

33
All notable changes to `laravel-api-response` will be documented in this file.
44

5-
## [Unreleased](https://github.com/kodepandai/laravel-api-response/compare/v1.2.0...main) - TBD
5+
## [Unreleased](https://github.com/kodepandai/laravel-api-response/compare/v1.3.0...main) - TBD
6+
7+
## [v1.3.0](https://github.com/kodepandai/laravel-api-response/compare/v1.2.0...v1.3.0) - 14 Dec 2022
68

79
### Fixed
810

9-
- Return 404 `NOT_FOUND` for laravel `ModelNotFoundException`
11+
- Laravel exception handler does not recognize Responsable trait ([#11](https://github.com/kodepandai/laravel-api-response/pull/11))
12+
- Return 404 `NOT_FOUND` for laravel `ModelNotFoundException` ([#10](https://github.com/kodepandai/laravel-api-response/pull/10))
13+
14+
### Added
15+
16+
- Support `Arrayable` interface for response data ([#13](https://github.com/kodepandai/laravel-api-response/pull/13))
1017

1118
## [v1.2.0](https://github.com/kodepandai/laravel-api-response/compare/v1.1.0...v1.2.0) - 24 Jul 2022
1219

README.md

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ use KodePandai\ApiResponse\ExceptionHandler as ApiExceptionHandler;
136136
public function register()
137137
{
138138
$this->renderable(function (Throwable $e, $request) {
139-
if ($request->wantsJson() || str_contains($request->path(), 'api')) {
139+
if ($request->wantsJson() || $request->is('*api*')) {
140140
return ApiExceptionHandler::renderAsApiResponse($e);
141141
}
142142
});
@@ -145,7 +145,7 @@ public function register()
145145
// old laravel (<= 7)
146146
public function render($request, Throwable $exception)
147147
{
148-
if ($request->wantsJson() || str_contains($request->path(), 'api')) {
148+
if ($request->wantsJson() || $request->is('*api*')) {
149149
return ApiExceptionHandler::renderAsApiResponse($exception);
150150
}
151151

@@ -155,8 +155,9 @@ public function render($request, Throwable $exception)
155155

156156
### Handling Exception Manually
157157

158-
If you want to handle all exceptions manually, please not that you must convert `ApiResponse` to `JsonResponse` by call
159-
`toResponse` method explicitly. See this example:
158+
If you want to handle exception manually,
159+
please note that you must convert `ApiResponse` to `JsonResponse`
160+
by calling `toResponse` method explicitly. See this example:
160161

161162
```php
162163
// file: Exception/Handler.php
@@ -167,7 +168,7 @@ public function register()
167168
$this->renderable(function (AuthenticationException $e, Request $request) {
168169
return ApiResponse::error()
169170
->message('Unauthorized')
170-
->statusCode(401)
171+
->statusCode(Response::HTTP_UNAUTHORIZED)
171172
->toResponse($request); // this part is required
172173
});
173174
}
@@ -178,7 +179,7 @@ public function render($request, Throwable $exception)
178179
if($exception instanceof AuthenticationException){
179180
return ApiResponse::error()
180181
->message('Unauthorized')
181-
->statusCode(401)
182+
->statusCode(Response::HTTP_UNAUTHORIZED)
182183
->toResponse($request); // this part is required
183184
}
184185

src/ApiResponse.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -62,12 +62,12 @@ public function addHeaders(array $headers): self
6262
public function toResponse($request): JsonResponse
6363
{
6464
return (new JsonResponse([
65-
'success' => $this->isSuccess,
66-
'title' => $this->title,
67-
'message' => $this->message,
68-
'data' => $this->data,
69-
'errors' => $this->errors,
70-
]))
65+
'success' => $this->isSuccess,
66+
'title' => $this->title,
67+
'message' => $this->message,
68+
'data' => $this->data,
69+
'errors' => $this->errors,
70+
]))
7171
->setStatusCode($this->statusCode)
7272
->withHeaders($this->headers);
7373
}
@@ -83,7 +83,7 @@ public static function create(): self
8383
/**
8484
* Return a success api response.
8585
*
86-
* @param array|Arrayable|JsonResource|ResourceCollection $data
86+
* @param array|Arrayable|Collection|JsonResource|ResourceCollection $data
8787
*/
8888
public static function success($data = []): self
8989
{
@@ -137,7 +137,7 @@ public static function validateOrFail(
137137
/**
138138
* Add data to response and transform according to its type.
139139
*
140-
* @param array|Arrayable|JsonResource|ResourceCollection $data
140+
* @param array|Arrayable|Collection|JsonResource|ResourceCollection $data
141141
*/
142142
public function data($data): self
143143
{

0 commit comments

Comments
 (0)