elm-pages 3.0.0-beta.32 → 3.0.0-beta.33

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -81,7 +81,7 @@ https://github.com/dillonkearns/elm-pages/projects
81
81
  You will see an error if the NPM and Elm package do not have a matching Compatibility Key. Usually it's best to upgrade to the latest version of both the Elm and NPM
82
82
  packages when you upgrade. However, in case you want to install versions that are behind the latest, the Compatibility Key is included here for reference.
83
83
 
84
- Current Compatibility Key: 12.
84
+ Current Compatibility Key: 13.
85
85
 
86
86
  ## Contributors ✨
87
87
 
@@ -1,3 +1,3 @@
1
- export const compatibilityKey = 12;
1
+ export const compatibilityKey = 13;
2
2
 
3
- export const packageVersion = "3.0.0-beta.32";
3
+ export const packageVersion = "3.0.0-beta.33";
@@ -91,6 +91,7 @@ export async function runGenerator(
91
91
  );
92
92
  return result;
93
93
  } catch (error) {
94
+ process.exitCode = 1;
94
95
  console.log(restoreColorSafe(error));
95
96
  }
96
97
  }
@@ -202,12 +202,26 @@ export function lookupOrPerform(
202
202
  },
203
203
  });
204
204
  } catch (error) {
205
- console.trace("@@@ request-cache2 HTTP error", error);
206
- reject({
207
- title: "BackendTask.Http Error",
208
- message: `${kleur.yellow().underline(request.url)} ${error.toString()}
209
- `,
210
- });
205
+ if (error.code === "ECONNREFUSED") {
206
+ resolve({
207
+ kind: "response-json",
208
+ value: { "elm-pages-internal-error": "NetworkError" },
209
+ });
210
+ } else if (
211
+ error.code === "ETIMEDOUT" ||
212
+ error.code === "ERR_SOCKET_TIMEOUT"
213
+ ) {
214
+ resolve({
215
+ kind: "response-json",
216
+ value: { "elm-pages-internal-error": "Timeout" },
217
+ });
218
+ } else {
219
+ console.trace("elm-pages unhandled HTTP error", error);
220
+ resolve({
221
+ kind: "response-json",
222
+ value: { "elm-pages-internal-error": "NetworkError" },
223
+ });
224
+ }
211
225
  }
212
226
  }
213
227
  });
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "elm-pages",
3
3
  "type": "module",
4
- "version": "3.0.0-beta.32",
4
+ "version": "3.0.0-beta.33",
5
5
  "homepage": "https://elm-pages.com",
6
6
  "moduleResolution": "node",
7
7
  "description": "Type-safe static sites, written in pure elm with your own custom elm-markup syntax.",
@@ -494,19 +494,25 @@ requestRaw request__ expect =
494
494
  (\maybeMockResolver rawResponseDict ->
495
495
  (case maybeMockResolver of
496
496
  Just mockResolver ->
497
- mockResolver request_
497
+ mockResolver request_ |> Maybe.map Ok
498
498
 
499
499
  Nothing ->
500
500
  rawResponseDict |> RequestsAndPending.get (request_ |> HashRequest.hash)
501
501
  )
502
502
  |> (\maybeResponse ->
503
503
  case maybeResponse of
504
- Just rawResponse ->
504
+ Just (Ok rawResponse) ->
505
505
  Ok rawResponse
506
506
 
507
507
  Nothing ->
508
508
  --Err (Pages.StaticHttpRequest.UserCalledStaticHttpFail ("INTERNAL ERROR - expected request" ++ request_.url))
509
509
  Err (BadBody Nothing ("INTERNAL ERROR - expected request" ++ request_.url))
510
+
511
+ Just (Err RequestsAndPending.NetworkError) ->
512
+ Err NetworkError
513
+
514
+ Just (Err RequestsAndPending.Timeout) ->
515
+ Err Timeout
510
516
  )
511
517
  |> Result.andThen
512
518
  (\(RequestsAndPending.Response maybeResponse body) ->
@@ -3,4 +3,4 @@ module Pages.Internal.Platform.CompatibilityKey exposing (currentCompatibilityKe
3
3
 
4
4
  currentCompatibilityKey : Int
5
5
  currentCompatibilityKey =
6
- 12
6
+ 13
@@ -1,4 +1,4 @@
1
- module RequestsAndPending exposing (RawResponse, RequestsAndPending, Response(..), ResponseBody(..), bodyEncoder, get)
1
+ module RequestsAndPending exposing (HttpError(..), RawResponse, RequestsAndPending, Response(..), ResponseBody(..), bodyEncoder, get)
2
2
 
3
3
  import Base64
4
4
  import Bytes exposing (Bytes)
@@ -101,11 +101,39 @@ responseDecoder =
101
101
  (Decode.field "url" Decode.string)
102
102
 
103
103
 
104
- get : String -> RequestsAndPending -> Maybe Response
104
+ get : String -> RequestsAndPending -> Maybe (Result HttpError Response)
105
105
  get key requestsAndPending =
106
106
  Decode.decodeValue
107
107
  (Decode.field key
108
- (Decode.field "response" decoder)
108
+ (Decode.field "response"
109
+ (Decode.oneOf
110
+ [ Decode.field "elm-pages-internal-error" errorDecoder |> Decode.map Err
111
+ , decoder |> Decode.map Ok
112
+ ]
113
+ )
114
+ )
109
115
  )
110
116
  requestsAndPending
111
117
  |> Result.toMaybe
118
+
119
+
120
+ type HttpError
121
+ = NetworkError
122
+ | Timeout
123
+
124
+
125
+ errorDecoder : Decoder HttpError
126
+ errorDecoder =
127
+ Decode.string
128
+ |> Decode.andThen
129
+ (\errorCode ->
130
+ case errorCode of
131
+ "NetworkError" ->
132
+ Decode.succeed NetworkError
133
+
134
+ "Timeout" ->
135
+ Decode.succeed Timeout
136
+
137
+ _ ->
138
+ Decode.fail "Unhandled error code."
139
+ )