Skip to content

Commit 6709399

Browse files
committed
Fixed Invalid Exception Key
1 parent a7425a9 commit 6709399

File tree

4 files changed

+25
-19
lines changed

4 files changed

+25
-19
lines changed
+21-2
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,31 @@
11
<?php
2+
23
namespace RakibDevs\Weather\Exceptions;
34

45
use Exception;
56

67
class InvalidConfiguration extends Exception
78
{
8-
public static function apiKeyNotSpecified()
9+
/**
10+
* Report the exception.
11+
*
12+
* @return void
13+
*/
14+
public function report()
15+
{
16+
//
17+
}
18+
19+
/**
20+
* Render the exception into an HTTP response.
21+
*
22+
* @param \Illuminate\Http\Request
23+
* @return \Illuminate\Http\Response
24+
*/
25+
public function render($request)
926
{
10-
return new static('There was no `api_key` specified. You must provide a valid API KEY to get weather data from Open Weather.');
27+
return response([
28+
'message' => 'Invalid API Key. Get a free Open Weather Map API key : https://openweathermap.org/price.'
29+
]);
1130
}
1231
}

src/Weather.php

-3
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,6 @@
1111
* @since 2021-01-09
1212
*/
1313

14-
use Illuminate\Support\Facades\Config;
15-
use RakibDevs\Weather\Exceptions\InvalidConfiguration;
16-
1714
class Weather
1815
{
1916
/**

src/WeatherClient.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
use GuzzleHttp\Exception\RequestException;
99
use GuzzleHttp\Exception\ServerException;
1010
use GuzzleHttp\Exception\TooManyRedirectsException;
11+
use RakibDevs\Weather\Exceptions\InvalidConfiguration;
1112
use RakibDevs\Weather\Exceptions\WeatherException;
1213

1314
class WeatherClient
@@ -68,7 +69,7 @@ protected function setApi()
6869
{
6970
$this->api_key = $this->config['api_key'];
7071
if ($this->api_key == '') {
71-
throw InvalidConfiguration::apiKeyNotSpecified();
72+
throw new InvalidConfiguration();
7273
}
7374
}
7475

src/config/openweather.php

+2-13
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,9 @@
88
*/
99

1010
'api_key' => '', // get an API key
11-
1211

1312
/**
14-
*
1513
* Library https://openweathermap.org/current#multi
16-
* af - Afrikaans
17-
al - Albanian
18-
ar - Arabic
19-
az - Azerbaijani
20-
bg - Bulgarian
21-
............
22-
more availabe language
2314
*
2415
*/
2516

@@ -30,12 +21,10 @@
3021
'day_format' => 'l',
3122

3223
/**
33-
* Units: available units are c, f, k.
24+
* Units: available units are c, f, k. (k is default)
3425
*
3526
* For temperature in Fahrenheit (f) and wind speed in miles/hour, use units=imperial
36-
* For temperature in Celsius (c) and wind speed in meter/sec, use units=metric
37-
* Temperature in Kelvin (k) and wind speed in meter/sec is used by default, so there is no need to use the units parameter in the API call if you want this
38-
*
27+
* For temperature in Celsius (c) and wind speed in meter/sec, use units=metric
3928
*/
4029

4130
'temp_format' => 'c',

0 commit comments

Comments
 (0)